【redis、jedis】使用ShardedJedisPool异常

异常栈:

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

Caused by: java.util.NoSuchElementException: Unable to validate object


原因:

使用ShardedJedisPool时,配了了多个redis服务器,并且配了testOnBorrow为true,当其中有redis服务器连接超时(防火墙等原因时),会出现以上错误。


解决:

配置ShardedJedisPool,首先应该用JedisPool测试是否每个redis服务是否可用。在本次异常中就是因为其中有一台redis服务连接超时,因为防火墙的原因。

你可能感兴趣的:(redis)