Jack
Jack

Reputation: 735

Access Redis connection pool using Spring Data Redis

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?

Upvotes: 0

Views: 885

Answers (1)

Jack
Jack

Reputation: 735

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();
    }
  }

Upvotes: 0

Related Questions