java - 使用Spring Data Redis访问Redis连接池

标签 java redis spring-data-redis jedis

我想监视并定期记录有关Redis连接池使用情况的信息。
我通过spring-data-redis RedisTemplate对象使用Redis。
有什么办法可以进入游泳池吗?

最佳答案

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

关于java - 使用Spring Data Redis访问Redis连接池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63883545/

相关文章:

java - 字符串格式通过 Java 的 SimpleDateFormat 可以正常工作,但不能通过 JodaTime 的 DateTimeFormat

java - 如何使用Gradle从CVS check out 项目?

redis - Redis 数据库中的 ZSET 是什么?

redis - 从过期键中检索值

node.js - 如何处理 node.js 库中未处理的异常

spring - 在 CloudFoundry 上为 Redis 实例配置哨兵节点

java - RandomAccessFile.close() 是否在内部调用 FileChannel.force()?

Java Streams - 缓冲巨大的流

java - Spring data redis - 多模式 - 在 session 中更改模式(获取连接)VS。使用多个连接池

java - JedisConnectionException - 读取超时错误