This error shows up after I upgraded spring-data-redis from 1.4.2 to 1.5.2.
My code is to implement a pessimistic lock,
redisTemplate.execute(new RedisCallback<Boolean>() {
@Override
public Boolean doInRedis(RedisConnection connection)
throws DataAccessException {
Boolean nx = connection.setNX(lockKey.getBytes(), identifier.getBytes());
return nx;
}};
Checked all fields not null. The setNx method always returns null. It should return boolean true or false.
Any help is appreciated.
Updates:
Above code snippet was nested in another SessionCallback
Redis transaction. It used to work under spring-data-redis 1.4.2. To fix "ERR EXEC without MULTI" reported at ERR EXEC without MULTI - spring redis+jedis, I upgraded the lib to 1.5.2, and the problem suddenly showed up.
To fix it, I first tried to assign a different redisTemplate (prototype bean) for the nested callback method, but it didn't work. The working solution is to break up and flatten the single transaction into 4, "test if lock is needed", "acquire lock", "do the business", "release lock".