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);