我已经看到几个线程中的答案,但没有为我工作,因为偶尔会出现问题,如果有任何人有任何想法,请问这个问题.
我使用的是jedis版本2.8.0,Spring Data redis版本1.7.5.和我们的缓存应用程序的redis服务器版本2.8.4.
我有多个缓存,用redis保存,get请求是从redis完成的.我使用spring数据redis API来保存和获取数据.
所有保存和获取工作正常,但偶尔低于例外:
Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool | org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the poolorg.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:198)
org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:345)
org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:129)
org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:92)
org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:79)
org.springframework.data.redis.core.Redistemplate.execute(Redistemplate.java:191)
org.springframework.data.redis.core.Redistemplate.execute(Redistemplate.java:166)
org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:88)
org.springframework.data.redis.core.DefaultHashOperations.get(DefaultHashOperations.java:49)
我的redis配置类:
@Configuration
public class RedisConfiguration {
@Value("${redisCentralCachingURL}")
private String redisHost;
@Value("${redisCentralCachingPort}")
private int redisPort;
@Bean
public StringRedisSerializer stringRedisSerializer() {
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
return stringRedisSerializer;
}
@Bean
JedisConnectionFactory jedisConnectionFactory() {
JedisConnectionFactory factory = new JedisConnectionFactory();
factory.setHostName(redisHost);
factory.setPort(redisPort);
factory.setUsePool(true);
return factory;
}
@Bean
public Redistemplatestemplate() {
Redistemplatestemplate = new Redistemplate<>();
redistemplate.setConnectionFactory(jedisConnectionFactory());
redistemplate.setExposeConnection(true);
// No serializer required all serialization done during impl
redistemplate.setKeySerializer(stringRedisSerializer());
//`redistemplate.setHashKeySerializer(stringRedisSerializer());
redistemplate.setHashValueSerializer(new GenericSnappyRedisSerializer());
redistemplate.afterPropertiesSet();
return redistemplate;
}
@Bean
public RedisCacheManager cacheManager() {
RedisCacheManager redisCacheManager = new RedisCacheManager(redistemplate());
redisCacheManager.setTransactionAware(true);
redisCacheManager.setLoadRemoteCachesOnStartup(true);
redisCacheManager.setUsePrefix(true);
return redisCacheManager;
}
}
有没有人遇到过这个问题或对此有任何想法,为什么会发生这种情况?
最佳答案
我们遇到了与RxJava相同的问题,应用程序运行良好,但过了一段时间后,再也无法从池中获取任何连接.经过几天的调试,我们终于找出了导致问题的原因:
redistemplate.setEnableTransactionSupport(true)
不知何故导致spring-data-redis不释放连接.我们需要对MULTI / EXEC的事务支持,但最终改变了实现以摆脱这个问题.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。