From 45a312ea2669c34276107b05827698d50d9979d1 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Fri, 15 Apr 2022 10:22:19 +0300 Subject: [PATCH] Fixed - an error should be thrown if merge(), compute(), computeIfAbsent() and computeIfPresent() of RMap used in batch #4229 --- .../main/java/org/redisson/RedissonMap.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/redisson/src/main/java/org/redisson/RedissonMap.java b/redisson/src/main/java/org/redisson/RedissonMap.java index dfa665226..881d63c66 100644 --- a/redisson/src/main/java/org/redisson/RedissonMap.java +++ b/redisson/src/main/java/org/redisson/RedissonMap.java @@ -28,10 +28,13 @@ import org.redisson.client.protocol.RedisCommands; import org.redisson.client.protocol.convertor.NumberConvertor; import org.redisson.client.protocol.decoder.MapValueDecoder; import org.redisson.command.CommandAsyncExecutor; +import org.redisson.command.CommandBatchService; import org.redisson.connection.decoder.MapGetAllDecoder; import org.redisson.iterator.RedissonMapIterator; import org.redisson.mapreduce.RedissonMapReduce; import org.redisson.misc.CompletableFutureWrapper; +import org.redisson.reactive.CommandReactiveBatchService; +import org.redisson.rx.CommandRxBatchService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -139,6 +142,12 @@ public class RedissonMap extends RedissonExpirable implements RMap { @Override public V merge(K key, V value, BiFunction remappingFunction) { + if (commandExecutor instanceof CommandBatchService + || commandExecutor instanceof CommandReactiveBatchService + || commandExecutor instanceof CommandRxBatchService) { + throw new IllegalStateException("This method doesn't work in batch mode."); + } + checkKey(key); checkValue(value); Objects.requireNonNull(remappingFunction); @@ -165,6 +174,12 @@ public class RedissonMap extends RedissonExpirable implements RMap { @Override public RFuture mergeAsync(K key, V value, BiFunction remappingFunction) { + if (commandExecutor instanceof CommandBatchService + || commandExecutor instanceof CommandReactiveBatchService + || commandExecutor instanceof CommandRxBatchService) { + throw new IllegalStateException("This method doesn't work in batch mode."); + } + checkKey(key); checkValue(value); Objects.requireNonNull(remappingFunction); @@ -208,6 +223,12 @@ public class RedissonMap extends RedissonExpirable implements RMap { @Override public RFuture computeAsync(K key, BiFunction remappingFunction) { + if (commandExecutor instanceof CommandBatchService + || commandExecutor instanceof CommandReactiveBatchService + || commandExecutor instanceof CommandRxBatchService) { + throw new IllegalStateException("This method doesn't work in batch mode."); + } + checkKey(key); Objects.requireNonNull(remappingFunction); @@ -264,6 +285,12 @@ public class RedissonMap extends RedissonExpirable implements RMap { @Override public V compute(K key, BiFunction remappingFunction) { + if (commandExecutor instanceof CommandBatchService + || commandExecutor instanceof CommandReactiveBatchService + || commandExecutor instanceof CommandRxBatchService) { + throw new IllegalStateException("This method doesn't work in batch mode."); + } + checkKey(key); Objects.requireNonNull(remappingFunction); @@ -288,6 +315,12 @@ public class RedissonMap extends RedissonExpirable implements RMap { @Override public RFuture computeIfAbsentAsync(K key, Function mappingFunction) { + if (commandExecutor instanceof CommandBatchService + || commandExecutor instanceof CommandReactiveBatchService + || commandExecutor instanceof CommandRxBatchService) { + throw new IllegalStateException("This method doesn't work in batch mode."); + } + checkKey(key); Objects.requireNonNull(mappingFunction); @@ -330,6 +363,12 @@ public class RedissonMap extends RedissonExpirable implements RMap { @Override public V computeIfAbsent(K key, Function mappingFunction) { + if (commandExecutor instanceof CommandBatchService + || commandExecutor instanceof CommandReactiveBatchService + || commandExecutor instanceof CommandRxBatchService) { + throw new IllegalStateException("This method doesn't work in batch mode."); + } + checkKey(key); Objects.requireNonNull(mappingFunction); @@ -353,6 +392,12 @@ public class RedissonMap extends RedissonExpirable implements RMap { @Override public RFuture computeIfPresentAsync(K key, BiFunction remappingFunction) { + if (commandExecutor instanceof CommandBatchService + || commandExecutor instanceof CommandReactiveBatchService + || commandExecutor instanceof CommandRxBatchService) { + throw new IllegalStateException("This method doesn't work in batch mode."); + } + checkKey(key); Objects.requireNonNull(remappingFunction); @@ -408,6 +453,12 @@ public class RedissonMap extends RedissonExpirable implements RMap { @Override public V computeIfPresent(K key, BiFunction remappingFunction) { + if (commandExecutor instanceof CommandBatchService + || commandExecutor instanceof CommandReactiveBatchService + || commandExecutor instanceof CommandRxBatchService) { + throw new IllegalStateException("This method doesn't work in batch mode."); + } + checkKey(key); Objects.requireNonNull(remappingFunction);