Fixed - RMap.keySet() throws NPE if CompositeCodec used. #5006

pull/5038/head
Nikita Koksharov 2 years ago
parent acb080fe91
commit f13ff2b4b5

@ -27,7 +27,7 @@ import org.redisson.client.codec.StringCodec;
import org.redisson.client.protocol.RedisCommand; import org.redisson.client.protocol.RedisCommand;
import org.redisson.client.protocol.RedisCommands; import org.redisson.client.protocol.RedisCommands;
import org.redisson.client.protocol.convertor.NumberConvertor; import org.redisson.client.protocol.convertor.NumberConvertor;
import org.redisson.client.protocol.decoder.MapValueDecoder; import org.redisson.client.protocol.decoder.*;
import org.redisson.command.CommandAsyncExecutor; import org.redisson.command.CommandAsyncExecutor;
import org.redisson.command.CommandBatchService; import org.redisson.command.CommandBatchService;
import org.redisson.connection.decoder.MapGetAllDecoder; import org.redisson.connection.decoder.MapGetAllDecoder;
@ -1484,14 +1484,17 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
} }
public RFuture<ScanResult<Object>> scanKeyIteratorAsync(String name, RedisClient client, long startPos, String pattern, int count) { public RFuture<ScanResult<Object>> scanKeyIteratorAsync(String name, RedisClient client, long startPos, String pattern, int count) {
List<Object> params = new ArrayList<Object>(); List<Object> params = new ArrayList<>();
params.add(startPos); params.add(startPos);
if (pattern != null) { if (pattern != null) {
params.add(pattern); params.add(pattern);
} }
params.add(count); params.add(count);
return commandExecutor.evalReadAsync(client, name, codec, RedisCommands.EVAL_SCAN, RedisCommand<ListScanResult<Object>> evalScan = new RedisCommand<ListScanResult<Object>>("EVAL",
new ListMultiDecoder2(new ListScanResultReplayDecoder(), new ObjectDecoder<>(codec.getMapKeyDecoder())));
return commandExecutor.evalReadAsync(client, name, codec, evalScan,
"local result = {}; " "local result = {}; "
+ "local res; " + "local res; "
+ "if (#ARGV == 3) then " + "if (#ARGV == 3) then "

@ -1573,11 +1573,6 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
params.toArray()); params.toArray());
} }
private static final RedisCommand<MapCacheKeyScanResult<Object>> KEY_SCAN = new RedisCommand<MapCacheKeyScanResult<Object>>("EVAL",
new ListMultiDecoder2(
new MapCacheKeyScanResultDecoder(),
new ObjectListReplayDecoder<>()));
@Override @Override
public RFuture<ScanResult<Object>> scanKeyIteratorAsync(String name, RedisClient client, long startPos, String pattern, int count) { public RFuture<ScanResult<Object>> scanKeyIteratorAsync(String name, RedisClient client, long startPos, String pattern, int count) {
List<Object> params = new ArrayList<>(); List<Object> params = new ArrayList<>();
@ -1588,7 +1583,10 @@ public class RedissonMapCache<K, V> extends RedissonMap<K, V> implements RMapCac
} }
params.add(count); params.add(count);
RFuture<MapCacheKeyScanResult<Object>> future = commandExecutor.evalReadAsync(client, name, codec, KEY_SCAN, RedisCommand<MapCacheKeyScanResult<Object>> evalScan = new RedisCommand<MapCacheKeyScanResult<Object>>("EVAL",
new ListMultiDecoder2(new MapCacheKeyScanResultDecoder(), new ObjectDecoder<>(codec.getMapKeyDecoder())));
RFuture<MapCacheKeyScanResult<Object>> future = commandExecutor.evalReadAsync(client, name, codec, evalScan,
"local result = {}; " "local result = {}; "
+ "local idleKeys = {}; " + "local idleKeys = {}; "
+ "local res; " + "local res; "

@ -878,7 +878,15 @@ public abstract class BaseMapTest extends BaseTest {
assertThat(map.size()).isEqualTo(1); assertThat(map.size()).isEqualTo(1);
destroy(map); destroy(map);
} }
@Test
public void testKeySetByPatternCodec() {
RMap<String, String> map = getMap("test", new CompositeCodec(StringCodec.INSTANCE, JsonJacksonCodec.INSTANCE));
map.put("1-1", "test1");
Set<String> set = map.keySet("1-*");
assertThat(set).containsOnly("1-1");
}
@Test @Test
public void testKeySetByPattern() { public void testKeySetByPattern() {
RMap<String, String> map = getMap("simple", StringCodec.INSTANCE); RMap<String, String> map = getMap("simple", StringCodec.INSTANCE);

Loading…
Cancel
Save