我用StringRedisTemplate可以从redis中获取数据
public String get(String key){
return (String)redisTemplate.opsForValue().get(key);
} ,但是用jedis连接池就会报错:JedisExhaustedPoolException: Could not get a resource since the pool is exhausted。检查了set和get方法都在finally里面释放了资源
/**
* 获取key的值
*/
public String getKey(String key) {
Jedis jedis = null;
String value = "";
try {
jedis = jedisPool.getResource();
value = jedis.get(key);
return value;
} catch (Exception e) {
e.printStackTrace();
} finally {
returnToPool(jedis);
}
return value;
}
private void returnToPool(Jedis jedis) {
if(jedis!=null){
jedis.close();
}
} 救救孩子!!!!
全部评论
(1) 回帖