J
J
Junior_WEB2022-03-09 22:16:08
Java
Junior_WEB, 2022-03-09 22:16:08

I am getting an error Cannot use Jedis when in Multi. Please use Transaction or reset jedis state How can I fix it?

Please tell me how can I fix this error.

"Cannot use Jedis when in Multi. Please use Transaction or reset jedis state".

I don't quite understand where and what exactly is wrong in the code.
I also follow two rules to make sure everything works. But it doesn't help.

1)Move all operations performed with jedis within this range, from the beginning of the transaction to the end of the transaction, outside this range.
2)Note: The get method of the Response object must be called after the transaction exec method is executed. Before the t.exec() method is executed, the Response object does not contain a result.

import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.exceptions.JedisConnectionException; 
import redis.clients.jedis.Jedis;
import java.util.ArrayList;
import java.util.List;
import redis.clients.jedis.Response;
import redis.clients.jedis.Transaction;
import redis.clients.jedis.JedisPool;

JedisPool jedisPool = (JedisPool) props.get('jedisPool');
Jedis jedis = jedisPool.getResource();


List<Object> execResult = null;
String profileCase;
int countTry = 0;
while(execResult == null) {
  try{
    jedis.watch("Delete_Choice");
    Transaction t = jedis.multi();  
    Response<String> rs = t.rpoplpush("Delete_Choice", "Delete_Choice");  
    execResult = t.exec();
    profileCase = rs.get();
    t.close();
    t = null;
    rs = null;
  } catch (Exception e){
    countTry++;
    sleep(50);
    if(countTry > 15){
      log.error("\r\nSome error (countTry = " + countTry + ") Delete_Choice: " + e.getMessage() + "\r\n");
    }    
  } finally {
     if(!jedis.isBroken())
            //jedisPool.returnResource(jedis);
            jedis.close();
    }
}
execResult.clear();

vars.put("Delete_Choice_JM", profileCase);

//jedisPool.returnResource(jedis);
jedis = null;
jedisPool = null;
profileCase = null;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question