【问题标题】:Access Redis connection pool using Spring Data Redis使用 Spring Data Redis 访问 Redis 连接池
【发布时间】:2021-01-01 03:08:07
【问题描述】:

我想监控并定期记录有关 Redis 连接池使用情况的信息。

我通过 spring-data-redis RedisTemplate 对象使用 Redis。

有没有办法访问池?

【问题讨论】:

    标签: java redis spring-data-redis jedis


    【解决方案1】:

    我能够使用反射 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();
        }
      }
    

    【讨论】:

      猜你喜欢
      • 2021-11-22
      • 1970-01-01
      • 2022-08-03
      • 1970-01-01
      • 2016-06-18
      • 2017-09-16
      • 1970-01-01
      • 2021-09-13
      • 2014-03-25
      相关资源
      最近更新 更多