fix(cache): exists 排除空值标记,与 get 口径一致
exists 原用 hasKey,会把持有空值标记的 key 判为"存在"(true),而 get 对同一 key 返回 null,二者口径打架。改为读值判断:空标记/缺失均返回 false,真实值返回 true。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -90,7 +90,9 @@ public class RedisCacheEnhanceTemplate {
|
||||
}
|
||||
|
||||
public boolean exists(String key) {
|
||||
return Boolean.TRUE.equals(redis.hasKey(keyBuilder.build(key)));
|
||||
// 与 get 口径一致:空值标记不算"存在"(物理 hasKey 会把空标记算存在,与 get→null 打架)
|
||||
String raw = redis.opsForValue().get(keyBuilder.build(key));
|
||||
return raw != null && !codec.isNullSentinel(raw);
|
||||
}
|
||||
|
||||
// ---- 续期 ----
|
||||
|
||||
Reference in New Issue
Block a user