From cc4573b4a8b7ec7b7f272766a6d707a5109e9742 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Fri, 10 Nov 2023 10:43:50 +0300 Subject: [PATCH] Fixed - RLocalCachedMap.containsKey() does not work properly if storeCacheMiss = true. #5411 --- .../org/redisson/RedissonLocalCachedMap.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java b/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java index 8e0a288f6..a0b69b5b6 100644 --- a/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java +++ b/redisson/src/main/java/org/redisson/RedissonLocalCachedMap.java @@ -233,13 +233,27 @@ public class RedissonLocalCachedMap extends RedissonMap implements R return new CompletableFutureWrapper<>(f); } - CompletableFuture promise = new CompletableFuture<>(); - promise.thenAccept(value -> { - if (storeCacheMiss || value != null) { - cachePut(cacheKey, key, value); + String name = getRawName(key); + RFuture future = containsKeyOperationAsync(name, key); + CompletionStage result = future.thenCompose(res -> { + if (hasNoLoader()) { + if (!res && storeCacheMiss) { + cachePut(cacheKey, key, null); + } + return CompletableFuture.completedFuture(res); + } + if (!res) { + CompletableFuture f = loadValue((K) key, false); + return f.thenApply(value -> { + if (storeCacheMiss || value != null) { + cachePut(cacheKey, key, value); + } + return value != null; + }); } + return CompletableFuture.completedFuture(res); }); - return containsKeyAsync(key, promise); + return new CompletableFutureWrapper<>(result); } return new CompletableFutureWrapper<>(cacheValue.getValue() != null);