![
Set sets = new HashSet<>();
sets.add(“192.168.1.5:26379”);
sets.add(“192.168.1.5:26380”);
sets.add(“192.168.1.5:26381”);
// GenericObjectPoolConfig config = new GenericObjectPoolConfig();
JedisSentinelPool jedisSentinelPool =new JedisSentinelPool(“mymaster”,sets);
int count =0;
while (true){
Jedis jedis =null;
try {
jedis = jedisSentinelPool.getResource();
int index = new Random().nextInt(100000);
String key = “key-”+index;
String value = “value-”+index;
jedis.set(key,value);
TimeUnit.MILLISECONDS.sleep(10);
if (count%100 == 0){
log.info(“key={},value={}”,key,value);
}
}catch (Exception e){
log.error(e.getMessage());
jedisSentinelPool.returnBrokenResource(jedis); //异常释放资源方法returnBrokenResource
jedisSentinelPool.returnResource(jedis); //正常释放资源方法returnResource
}finally {
if (jedis!=null){
jedis.close();
}
}
报错Could not get a resource from the pool