在使用jedis并发时,发现总出现一个bug,使用了连接池,总是报
java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Long
at redis.clients.jedis.Connection.getIntegerReply(Connection.java:161)
at redis.clients.jedis.Jedis.del(Jedis.java:108)
这是因为jedis没有将破坏的jedis对象抛弃掉,所以catch时要加上returnBrokenResource(jedis);
public long select (String key) {
Jedis jedis = null;try {
jedis = getJedis();
Object obj = jedis.del(key);
} catch (Exception e) {
returnBrokenResource(jedis);
}
finally
{
releaseJedisInstance(jedis);
}
return rt;
}