From eedd7b0f15d95944c2328b42e79dd9f3175d05e5 Mon Sep 17 00:00:00 2001 From: xujie Date: Tue, 7 Sep 2021 20:39:09 +0800 Subject: [PATCH] fix: fix bug for mset cross slot (miss values except cluster mode) Signed-off-by: xujie --- .../java/org/redisson/RedissonBuckets.java | 2 +- .../command/CommandAsyncExecutor.java | 5 +++- .../redisson/command/CommandAsyncService.java | 27 ++++++++++++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/redisson/src/main/java/org/redisson/RedissonBuckets.java b/redisson/src/main/java/org/redisson/RedissonBuckets.java index d73b19e8d..a3f4d6701 100644 --- a/redisson/src/main/java/org/redisson/RedissonBuckets.java +++ b/redisson/src/main/java/org/redisson/RedissonBuckets.java @@ -150,7 +150,7 @@ public class RedissonBuckets implements RBuckets { } return params.toArray(); } - }, buckets.keySet().toArray(new String[]{})); + }, buckets.keySet().toArray(new String[]{}), buckets); } } diff --git a/redisson/src/main/java/org/redisson/command/CommandAsyncExecutor.java b/redisson/src/main/java/org/redisson/command/CommandAsyncExecutor.java index e1e970b02..73f65281e 100644 --- a/redisson/src/main/java/org/redisson/command/CommandAsyncExecutor.java +++ b/redisson/src/main/java/org/redisson/command/CommandAsyncExecutor.java @@ -28,6 +28,7 @@ import org.redisson.liveobject.core.RedissonObjectBuilder; import java.util.Collection; import java.util.List; +import java.util.Map; /** * @@ -115,7 +116,9 @@ public interface CommandAsyncExecutor { ByteBuf encodeMapValue(Codec codec, Object value); RFuture readBatchedAsync(Codec codec, RedisCommand command, SlotCallback callback, String... keys); - + RFuture writeBatchedAsync(Codec codec, RedisCommand command, SlotCallback callback, String... keys); + RFuture writeBatchedAsync(Codec codec, RedisCommand command, SlotCallback callback, String[] keys, Map valueMap); + } diff --git a/redisson/src/main/java/org/redisson/command/CommandAsyncService.java b/redisson/src/main/java/org/redisson/command/CommandAsyncService.java index e34f2c51a..b7a4b6f77 100644 --- a/redisson/src/main/java/org/redisson/command/CommandAsyncService.java +++ b/redisson/src/main/java/org/redisson/command/CommandAsyncService.java @@ -588,20 +588,35 @@ public class CommandAsyncService implements CommandAsyncExecutor { @Override public RFuture readBatchedAsync(Codec codec, RedisCommand command, SlotCallback callback, String... keys) { - return executeBatchedAsync(true, codec, command, callback, keys); + return executeBatchedAsync(true, codec, command, callback, keys, null); } - + @Override public RFuture writeBatchedAsync(Codec codec, RedisCommand command, SlotCallback callback, String... keys) { - return executeBatchedAsync(false, codec, command, callback, keys); + return executeBatchedAsync(false, codec, command, callback, keys, null); + } + + @Override + public RFuture writeBatchedAsync(Codec codec, RedisCommand command, SlotCallback callback, String[] keys, Map valueMap) { + return executeBatchedAsync(false, codec, command, callback, keys, valueMap); } - private RFuture executeBatchedAsync(boolean readOnly, Codec codec, RedisCommand command, SlotCallback callback, String... keys) { + private RFuture executeBatchedAsync(boolean readOnly, Codec codec, RedisCommand command, SlotCallback callback, String[] keys, Map valueMap) { if (!connectionManager.isClusterMode()) { + List params = null; + if (valueMap != null) { + params = new ArrayList<>(keys.length * 2); + for (String key : keys) { + params.add(key); + params.add(valueMap.get(key)); + } + } else { + params = Arrays.asList(keys); + } if (readOnly) { - return readAsync((String) null, codec, command, keys); + return readAsync((String) null, codec, command, params.toArray()); } - return writeAsync((String) null, codec, command, keys); + return writeAsync((String) null, codec, command, params.toArray()); } Map>> entry2keys = Arrays.stream(keys).collect(