Improvement - JsonBucket.compareAndSet with null as update value deletes whole object. #4592

pull/4597/head
Nikita Koksharov 2 years ago
parent a5f0964fbd
commit 43314fe978

@ -296,7 +296,7 @@ public class RedissonJsonBucket<V> extends RedissonExpirable implements RJsonBuc
if (update == null) {
return commandExecutor.evalWriteAsync(getRawName(), codec, RedisCommands.EVAL_BOOLEAN,
"if redis.call('json.get', KEYS[1], ARGV[1]) == ARGV[2] then "
+ "redis.call('json.del', KEYS[1]); "
+ "redis.call('json.del', KEYS[1], ARGV[1]); "
+ "return 1 "
+ "else "
+ "return 0 end;",

@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import org.junit.jupiter.api.Test;
import org.redisson.api.JsonType;
import org.redisson.api.RJsonBucket;
import org.redisson.client.codec.StringCodec;
import org.redisson.codec.JacksonCodec;
import java.math.BigDecimal;
@ -70,6 +71,16 @@ public class RedissonJsonBucketTest extends BaseTest {
}
}
@Test
public void testCompareAndSetUpdate() {
RJsonBucket<String> b = redisson.getJsonBucket("test", StringCodec.INSTANCE);
b.set("{\"foo\": false, \"bar\":true}");
boolean s = b.compareAndSet("$.foo", false, null);
assertThat(s).isTrue();
boolean result = b.isExists();
assertThat(result).isTrue();
}
@Test
public void testType() {
RJsonBucket<TestType> al = redisson.getJsonBucket("test", new JacksonCodec<>(TestType.class));

Loading…
Cancel
Save