Cannot use Jedis when in Multi. Please use Transation or reset jedis state.
2016-08-30 23:27
1656 查看
使用jedis的transaction时,执行如下代码会报异常:
Jedis conn = new Jedis("localhost");
conn.select(0);
异常如下:
原因:
如果使用了jedis的事务,那么在事务中,需要用事务的实例(Transaction实例)来执行命令,最后调用exec执行事务模块中的命令。如果不小心使用了conn连接(Jedis实例)直接执行命令,则会抛出以上的异常。
Jedis conn = new Jedis("localhost");
conn.select(0);
Transaction trans = conn.multi();
conn.hdel("count:" + counter, pair.getKey() + "");
trans.exec();
异常如下:
redis.clients.jedis.exceptions.JedisDataException: Cannot use Jedis when in Multi. Please use Transation or reset jedis state.
原因:
如果使用了jedis的事务,那么在事务中,需要用事务的实例(Transaction实例)来执行命令,最后调用exec执行事务模块中的命令。如果不小心使用了conn连接(Jedis实例)直接执行命令,则会抛出以上的异常。
相关文章推荐
- Cannot use Jedis when in Multi. Please use Transation or reset jedis state.
- 打开Eclipse提示“The default workspace “xxxx” is in use or cannot be created Please choose a different on
- 打开Eclipse提示“The default workspace “xxxx” is in use or cannot be created Please choose a different on
- The default workspace “xxxx” is in use or cannot be created Please choose a different one“
- 无法打开Eclipse:The default workspace “xxx” is in use or cannot be created Please choose a different one
- 搬砖中的小事之工具(三)--Eclipse报错The default workspace“xxxx” is in use or cannot be created Please choose...
- eclipse提示“the default workspace "D:/*****"is in use or cannot be created.Please choose a different”
- 打开Eclipse提示“The default workspace “xxxx” is in use or cannot be created Please choose a different one“
- 打开Eclipse提示“The default workspace “xxxx” is in use or cannot be created Please choose a different on
- curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in
- Workspace in useor cannot be created, choose a different one.--错误解决办法
- Cannot start session without errors, please check errors given in your PHP and/or webserver log file
- 记一次Maven 打包multi-catch statement is not supported in -source 1.5 [ERROR] (use -source 7 or higher to
- eclipse 打开出现:Workspace in use or cannot be created, choose a different one
- Workspace in use or cannot be created, choose a different one.--错误解决办法
- You receive a "Setup Library wbemupgd.dll could not be loaded" error message when you use Add or Remove Programs in Windows Server 2003
- 打开Eclipse时:Workspace in use or cannot be created, choose a different one.–错误解决办法
- Workspace in useor cannot be created, choose a different one.--错误解决办法
- eclipse 报错:Workspace in use or cannot be created, choose a different one.
- myeclipse打开时出现"Workspace in use or cannot be created, choose a different one."怎么解决