首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Spring Data Redis访问Redis连接池

使用Spring Data Redis访问Redis连接池
EN

Stack Overflow用户
提问于 2020-09-14 19:39:40
回答 1查看 242关注 0票数 0

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

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

有没有办法进入游泳池?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-24 21:52:10

我能够使用反射API访问内部池。

代码语言:javascript
运行
复制
  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();
    }
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63883545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档