java - 使用 Spring Data Redis 访问 Redis 连接池
问题描述
我想监视并定期记录有关 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();
}
}
推荐阅读
- react-native - 如何在反应原生地图中按按钮打印纬度?
- python - 如何终止调用 python 多处理的 ssh 会话
- kubernetes - helm init 错误:安装时出错:在 gitlab runner 中运行时禁止部署.extensions
- tensorflow - Tensorflow 中的张量可以有非连续内存吗?
- apache - 为什么我会收到 500 内部服务器错误和 Apache 错误,并超出内部重定向?
- java - FileSystemPersistentAcceptOnceFileListFilter 与 MongoDB 元数据存储重复文件处理
- audit - 使用 ExaPlus 创建哪些 SQL 查询以在左侧生成菜单(模式、表和视图、.. 连接)?
- intel-pin - Intel PIN:当工具中发生段错误时打印回溯
- html - 放大时将文本放入容器
- jquery - 右括号在那里,为什么它说它缺少括号?