我想监控并定期记录有关Redis连接池使用情况的信息。
我通过spring-data-redis RedisTemplate对象使用Redis。
有没有办法进入游泳池?
发布于 2020-09-24 21:52:10
我能够使用反射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();
}
}https://stackoverflow.com/questions/63883545
复制相似问题