I get the following error
WARN r.c.j.JedisFactory: Error while close
redis.clients.jedis.exceptions.JedisException: Could not return the broken resource to the pool
Please tell me how it can be fixed. Because I get this error regularly. I think that there is an additional need to wrap something in "try" and "catch". Or is there a problem in something else ? I will be glad to help.
The code looks like this.
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;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.exceptions.JedisConnectionException;
import java.time.Duration;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.jmeter.samplers.SampleResult;
JedisPool jedisPool = (JedisPool) props.get('jedisPool');
Jedis jedis = jedisPool.getResource();
List<Object> execResult = null;
String GetIncrNumber;
int countTry = 0;
while(execResult == null) {
try{
jedis.watch("Number");
Transaction t = jedis.multi();
Response<String> rs = t.incr("Number");
execResult = t.exec();
GetIncrNumber = rs.get();
t.close();
t = null;
rs = null;
} catch (Exception e){
countTry++;
sleep(50);
if(countTry > 15){
log.error("\r\nSome error (countTry = " + countTry + ") GetIncrNumber: " + e.getMessage() + "\r\n");
}
}
}
execResult.clear();
vars.put("GetIncrNumber_JM", GetIncrNumber.toString());
//log.info(GetIncrNumber)
jedisPool.returnResource(jedis);
execResult = null;
jedis = null;
jedisPool = null;
Maybe you should call JedisPool.returnBrokenResource() somewhere in finally block and catching more specific exception?
you can also consider using Jedis.close() instead.
By the way, have you considered using Redis Data Set Config instead of writing the custom code?