gpt4 book ai didi

java - redis.clients.jedis.exceptions.JedisConnectionException : Could not get a resource from the pool

转载 作者:可可西里 更新时间:2023-11-01 11:00:16 25 4
gpt4 key购买 nike

我试图用 spring Boot 实现 redis,我在我的本地主机上随机遇到以下异常:

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool;

我已经尝试过 JedisPoolConfig 的各种属性组合。但是他们都没有帮助不确定哪里出了问题。

@Configuration
public class RedisConfigurationSetup {
@Bean
public RedisConnectionFactory jedisConnectionFactory() {
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(10000);
poolConfig.setMinIdle(1000);
poolConfig.setMaxIdle(-1);
poolConfig.setMaxWaitMillis(500);
poolConfig.setTestOnBorrow(true);
poolConfig.setTestOnReturn(true);
JedisConnectionFactory ob = new JedisConnectionFactory(poolConfig);
ob.setHostName("127.0.0.1");
ob.setPort(6379);
ob.setUsePool(true);
return ob;
}

@SuppressWarnings({ "rawtypes" })
@Bean(name = "redisTemplate")
public RedisTemplate stringRedisTemplate() {
RedisTemplate rt = new RedisTemplate();
rt.setConnectionFactory(jedisConnectionFactory());
rt.setEnableTransactionSupport(true);
return rt;
}
}


public class GeoLocationCacheServiceImpl implements GeoLocationCacheService {

@Autowired
@Qualifier("redisTemplate")
RedisTemplate geoObjectRedisTemplate;

@Override
public void saveUpdateGeoLoc(GeoObject geoObject) {

if (geoObject != null) {
// Some Business logics
geoObjectRedisTemplate.opsForValue().set(geoObject.getObjectID(), geoObject);
// Some Business logics
}
}
}

最佳答案

因为 rt.setEnableTransactionSupport(true);而从源码中我们可以看出

if (!enableTransactionSupport) {
RedisConnectionUtils.releaseConnection(conn, factory);
}

关于java - redis.clients.jedis.exceptions.JedisConnectionException : Could not get a resource from the pool,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27774957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com