I want to monitor and periodically log information about the Redis Connection Pool usage.
I use Redis through spring-data-redis RedisTemplate object.
Is there any way to access pool?
I was able to access internal pool using reflection API.
private GenericObjectPool<Jedis> jedisPool() {
try {
Field pool = JedisConnectionFactory.class.getDeclaredField("pool");
pool.setAccessible(true);
Pool<Jedis> jedisPool = (Pool<Jedis>) pool.get(jedisConnectionFactory());
Field internalPool = Pool.class.getDeclaredField("internalPool");
internalPool.setAccessible(true);
return (GenericObjectPool<Jedis>) internalPool.get(jedisPool);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}