Fixed - RJsonBucket.getKeys() method doesn't user path param

pull/4502/head
Nikita Koksharov 2 years ago
parent 94b08c23d7
commit ac9a4ad375

@ -251,23 +251,7 @@ public class RedissonJsonBucket<V> extends RedissonExpirable implements RJsonBuc
return trySetAsync(update);
}
if (update == null) {
return commandExecutor.evalWriteAsync(getRawName(), codec, RedisCommands.EVAL_BOOLEAN,
"if redis.call('json.get', KEYS[1]) == ARGV[1] then "
+ "redis.call('json.del', KEYS[1]); "
+ "return 1 "
+ "else "
+ "return 0 end;",
Collections.singletonList(getRawName()), encode(expect));
}
return commandExecutor.evalWriteAsync(getRawName(), codec, RedisCommands.EVAL_BOOLEAN,
"if redis.call('json.get', KEYS[1]) == ARGV[1] then "
+ "redis.call('json.set', KEYS[1], '$', ARGV[2]); "
+ "return 1 "
+ "else "
+ "return 0 end",
Collections.singletonList(getRawName()), encode(expect), encode(update));
return compareAndSetUpdateAsync("$", expect, update);
}
@Override
@ -293,6 +277,10 @@ public class RedissonJsonBucket<V> extends RedissonExpirable implements RJsonBuc
expect = Arrays.asList(expect);
}
return compareAndSetUpdateAsync(path, expect, update);
}
protected RFuture<Boolean> compareAndSetUpdateAsync(String path, Object expect, Object update) {
if (update == null) {
return commandExecutor.evalWriteAsync(getRawName(), codec, RedisCommands.EVAL_BOOLEAN,
"if redis.call('json.get', KEYS[1], ARGV[1]) == ARGV[2] then "
@ -783,7 +771,7 @@ public class RedissonJsonBucket<V> extends RedissonExpirable implements RJsonBuc
@Override
public RFuture<List<String>> getKeysAsync(String path) {
return commandExecutor.readAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.JSON_OBJKEYS, getRawName());
return commandExecutor.readAsync(getRawName(), LongCodec.INSTANCE, RedisCommands.JSON_OBJKEYS, getRawName(), path);
}
@Override

@ -717,9 +717,9 @@ public interface RedisCommands {
RedisCommand<List<Long>> JSON_OBJLEN_LIST = new RedisCommand("JSON.OBJLEN", new ObjectListReplayDecoder<Long>(), new LongReplayConvertor());
RedisCommand<List<String>> JSON_OBJKEYS = new RedisCommand("JSON.OBJKEYS", new StringListReplayDecoder());
RedisCommand<List<String>> JSON_OBJKEYS = new RedisCommand("JSON.OBJKEYS", new StringListListReplayDecoder());
RedisCommand<List<List<String>>> JSON_OBJKEYS_LIST = new RedisCommand("JSON.OBJKEYS", new StringListReplayDecoder());
RedisCommand<List<List<String>>> JSON_OBJKEYS_LIST = new RedisCommand("JSON.OBJKEYS", new StringListListReplayDecoder());
RedisCommand<Boolean> JSON_TOGGLE = new RedisCommand<Boolean>("JSON.TOGGLE", new BooleanReplayConvertor());

@ -0,0 +1,19 @@
package org.redisson.client.protocol.decoder;
import org.redisson.client.handler.State;
import java.util.List;
public class StringListListReplayDecoder extends StringListReplayDecoder {
@Override
public List<String> decode(List<Object> parts, State state) {
for (Object part : parts) {
if (part instanceof List) {
return (List<String>) (Object) parts;
}
}
return super.decode(parts, state);
}
}

@ -344,6 +344,20 @@ public class RedissonJsonBucketTest extends BaseTest {
assertThat(nt3.getValues()).isEqualTo(nt2.getValues());
}
@Test
public void testKeys() {
RJsonBucket<String> jb = redisson.getJsonBucket("test", StringCodec.INSTANCE);
jb.set("{\"a\":false, \"nested\": {\"a\": {\"b\":2, \"c\": 1, \"d\": 3}}}");
List<String> keys1 = jb.getKeys();
assertThat(keys1).containsExactly("a", "nested");
List<String> keys3 = jb.getKeys("nested.a");
assertThat(keys3).containsExactly("b", "c", "d");
List<List<String>> keys5 = jb.getKeysMulti("$.nested.a");
assertThat(keys5).isEqualTo(Arrays.asList(Arrays.asList("b", "c", "d")));
}
@Test
public void testCompareAndSet() {

Loading…
Cancel
Save