NutzCN Logo
问答 jedis 通道使用报错
发布于 2632天前 作者 Rekoe 2306 次浏览 复制 上一个帖子 下一个帖子
标签:

错误这样

05:49:30.749 [main] ERROR com.anawin.tools.IocProvider - Please close pipeline or multi block before calling this method.
redis.clients.jedis.exceptions.JedisDataException: Please close pipeline or multi block before calling this method.
	at redis.clients.jedis.Response.get(Response.java:33) ~[jedis-2.9.0.jar:?]
	at com.anawin.quartz.job.CtrJob.execute(CtrJob.java:118) ~[om_tools.jar:?]
	at com.anawin.quartz.job.CtrJob$$NUTZAOP._aop_invoke(CtrJob.java:1) ~[nutz-1.r.63-SNAPSHOT.jar:?]
	at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77) ~[nutz-1.r.63-SNAPSHOT.jar:1.r.63-SNAPSHOT]
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57) ~[nutz-1.r.63-SNAPSHOT.jar:1.r.63-SNAPSHOT]
	at org.nutz.integration.jedis.RedisInterceptor.filter(RedisInterceptor.java:24) ~[nutz-integration-jedis-1.r.62.jar:?]
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60) ~[nutz-1.r.63-SNAPSHOT.jar:1.r.63-SNAPSHOT]
	at com.anawin.quartz.job.CtrJob$$NUTZAOP.execute(CtrJob.java:1) ~[nutz-1.r.63-SNAPSHOT.jar:?]
	at com.anawin.tools.IocProvider.me(IocProvider.java:55) [om_tools.jar:?]
	at com.anawin.tools.IocProvider.main(IocProvider.java:88) [om_tools.jar:?]

用的code

Pipeline p = jedis.pipelined();
Response<String> omObj = p.hget("om.ctr", "rekoe");
omObj.get();
8 回复

要先执行pipeline.multi(),然后才能取值

另外,集群不支持pipeline,分片也不支持pipeline的

每次 omObj.get(); 前调用 还是 jedis.pipelined() 后调用一次

两者都没用

omObj.get() 之前仅调用一次

Pipeline p = jedis.pipelined();

			for (String id : ids) {
				Response<String> omObj = p.hget("om.ctr", id);
				p.multi();
				long number = Castors.me().castTo(omObj.get(), long.class);
				p.hset("om.ctr", id, (number + 1) + "");
			}
			p.sync();

还是提示这个错误

完全错误啦... pipeline是收集全部操作,然后发送给服务器,然后全部取回结果.

                        Pipeline p = jedis.pipelined();
                        List<Response<String>> resps = new ArrayList<>();
			for (String id : ids) {
				Response<String> omObj = p.hget("om.ctr", id);
				resps.add(omObj);
			}
			p.sync();
			for (Response<String> resp : resps) {
				long number = Castors.me().castTo(omObj.get(), long.class);
				jedis.hset("om.ctr", id, (number + 1) + "");
                        }

再说了, 你需要的是hincr, 并不需要hget+hset

我是需要统计一堆id的累加值

添加回复
请先登陆
回到顶部