Alw*_*ing 16 java spring redis spring-data-redis spring-boot
我正在使用用于缓存的spring-boot spring-data-redis 1.8.9.RELEASE RedisCacheManager实现CacheManager.我想要查看的一个指标是缓存命中/未命中率.为了实现这一点,我正在提取通过redis服务器公开的keyspace_hits和keyspace_misses,也可以通过redis_cli查看INFO STATS
.问题是RedisCacheManager从不注册缓存未命中,即即使存在缓存"未命中",keyspace_misses也不会增加.
调试代码,我看到spring-data-redis实际上EXISTS
在检索之前检查redis中的密钥.我看到了这种方法的意义,但是当EXISTS
对redis服务器执行时,它没有注册缓存未命中.
有没有办法使用RedisCacheManager并注册缓存未命中?我知道我可以使用其他redis对象来实现这一目标,但我想知道是否可以使用标准的CacheManager实现来完成它?
编辑
理想的解决方案不会增加大量开销,我无法编辑redis服务器的配置.
RedisCacheManager从缓存中检索元素时使用的代码.通知Boolean exists
:
public RedisCacheElement get(final RedisCacheKey cacheKey) {
Assert.notNull(cacheKey, "CacheKey must not be null!");
Boolean exists = (Boolean)this.redisOperations.execute(new RedisCallback<Boolean>() {
public Boolean doInRedis(RedisConnection connection) throws DataAccessException {
return connection.exists(cacheKey.getKeyBytes());
}
});
return !exists ? null : new RedisCacheElement(cacheKey, this.fromStoreValue(this.lookup(cacheKey)));
}
Run Code Online (Sandbox Code Playgroud)
上面的代码将通过MONITOR
高速缓存未命中在redis 上执行这些命令.再次注意,EXISTS
根据代码执行:
执行上述命令后,keyspace_misses
即使存在高速缓存未命中,也不会递增:
小智 1
问题中提到的代码是Spring提供的RedisCache的一部分。
归档时间: |
|
查看次数: |
508 次 |
最近记录: |