Jedis中的响应对象 - 抛出ClassCastException

时间:2013-04-22 17:08:28

标签: java response sync pipeline jedis

在Jedis中使用Response Object,抛出ClassCastException。当我使用管道时,我无法从Redis获得任何价值。请帮忙。我正在使用Jedis 2.1.0

public class JedisPipeline {    
    public static void main(String args[]){
        final JedisPool pool = new JedisPool(new JedisPoolConfig(), "127.0.0.1", 6379);
        Jedis jedis = pool.getResource();
        Pipeline pipeline = jedis.pipelined();
        pipeline.multi();
        HashMap<String,String> map = new HashMap<String,String>();
        map.put("50", "50");
        pipeline.hmset("Id",map);
        Response <Long> incr = pipeline.hincrBy("Id", "100", 100);
        Response<Map<String,String>> map1 = pipeline.hgetAll("Id");
        pipeline.exec();
        List<Object> results = pipeline.syncAndReturnAll();
        System.out.println(results);
        System.out.println( incr.get());
        System.out.println( map1.get());
        pool.returnResource(jedis);
        pool.destroy();
    }
}

Exception in thread "main" java.lang.ClassCastException: [B cannot be cast to java.lang.Long
    at redis.clients.jedis.BuilderFactory$4.build(BuilderFactory.java:45)
    at redis.clients.jedis.BuilderFactory$4.build(BuilderFactory.java:48)
    at redis.clients.jedis.Response.get(Response.java:27)
    at redis.clients.jedis.Pipeline.syncAndReturnAll(Pipeline.java:42)
    at com.work.jedis.JedisPipeline.main(JedisPipeline.java:28)

1 个答案:

答案 0 :(得分:4)

我使用的jar文件存在冲突。我在构建路径中错误地保留了jedis 2.1.0和jedis 2.0.0。