没有 MULTI 的 ERR EXEC - Jedis [英] ERR EXEC without MULTI - Jedis
本文介绍了没有 MULTI 的 ERR EXEC - Jedis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习 jedis,我无法确切地找出这段代码中的问题所在.任何人都可以帮助我.异常发生在语句 tx.exec()
I'm learning jedis, I couldn't exactly find out what is the problem in this code. Can anyone help me.The exception occurs at the statement tx.exec()
public class JedisFactory {
public static void main (String [] args){
JedisPool pool = new JedisPool(new JedisPoolConfig(), "127.0.0.1", 6379);
Jedis jedis = pool.getResource();
Pipeline pipeline = jedis.pipelined();
for(int i=0; i < 1000 ; i++){
pipeline.hincrBy("Id", i+"", i);
}
pipeline.exec();
pool.returnResource(jedis);
jedis = pool.getResource();
Transaction tx = jedis.multi();
Response<Map<String,String>> map = tx.hgetAll("Id");
tx.hincrBy("Id","2", 1);
**tx.exec();**
//Map<String,String> map1 = jedis.hgetAll("Id");
pool.returnResource(jedis);
pool.destroy();
}
}
Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: ERR EXEC without MULTI
at redis.clients.jedis.Protocol.processError(Protocol.java:54)
at redis.clients.jedis.Protocol.process(Protocol.java:61)
at redis.clients.jedis.Protocol.read(Protocol.java:122)
at redis.clients.jedis.Connection.getAll(Connection.java:207)
at redis.clients.jedis.BinaryTransaction.exec(BinaryTransaction.java:23)
at com.work.JedisFactory.main(JedisFactory.java:30)
推荐答案
在 for 循环之前添加 pipeline.multi() 解决了问题.但是在修复之前在其他行抛出的异常.
Adding pipeline.multi() before for loop solved the problem. But the exception thrown at some other line before the fix.
这篇关于没有 MULTI 的 ERR EXEC - Jedis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文