redis pool: don't reuse broken jedis instances
This commit is contained in:
@@ -27,17 +27,22 @@ package net.runelite.http.service.util.redis;
|
|||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@Slf4j
|
||||||
public class RedisPool
|
public class RedisPool
|
||||||
{
|
{
|
||||||
|
private final String redisHost;
|
||||||
private final BlockingQueue<Jedis> queue;
|
private final BlockingQueue<Jedis> queue;
|
||||||
|
|
||||||
RedisPool(@Value("${redis.pool.size:10}") int queueSize, @Value("${redis.host:localhost}") String redisHost)
|
RedisPool(@Value("${redis.pool.size:10}") int queueSize, @Value("${redis.host:localhost}") String redisHost)
|
||||||
{
|
{
|
||||||
|
this.redisHost = redisHost;
|
||||||
|
|
||||||
queue = new ArrayBlockingQueue<>(queueSize);
|
queue = new ArrayBlockingQueue<>(queueSize);
|
||||||
for (int i = 0; i < queueSize; ++i)
|
for (int i = 0; i < queueSize; ++i)
|
||||||
{
|
{
|
||||||
@@ -73,8 +78,25 @@ public class RedisPool
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close()
|
public void close()
|
||||||
|
{
|
||||||
|
if (!getClient().isBroken())
|
||||||
{
|
{
|
||||||
queue.offer(this);
|
queue.offer(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.warn("jedis client is broken, creating new client");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
log.warn("unable to close broken jedis", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
queue.offer(new PooledJedis(redisHost));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user