Use Long.parseUnsignedLong/toUnsignedString for SCAN cursor id parsing.
Redis uses an unsigned 64bit value for its cursor id which is now captured via parseUnsignedLong. Closes: #2796
This commit is contained in:
committed by
Christoph Strobl
parent
966dc05704
commit
b9f2e4c509
@@ -279,9 +279,10 @@ class JedisClusterHashCommands implements RedisHashCommands {
|
||||
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
|
||||
ScanResult<Entry<byte[], byte[]>> result = connection.getCluster().hscan(key, JedisConverters.toBytes(cursorId),
|
||||
ScanResult<Entry<byte[], byte[]>> result = connection.getCluster().hscan(key,
|
||||
JedisConverters.toBytes(Long.toUnsignedString(cursorId)),
|
||||
params);
|
||||
return new ScanIteration<>(Long.valueOf(result.getCursor()), result.getResult());
|
||||
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()), result.getResult());
|
||||
}
|
||||
}.open();
|
||||
}
|
||||
|
||||
@@ -180,8 +180,8 @@ class JedisClusterKeyCommands implements RedisKeyCommands {
|
||||
protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
|
||||
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
ScanResult<String> result = client.scan(Long.toString(cursorId), params);
|
||||
return new ScanIteration<>(Long.valueOf(result.getCursor()),
|
||||
ScanResult<String> result = client.scan(Long.toUnsignedString(cursorId), params);
|
||||
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()),
|
||||
JedisConverters.stringListToByteList().convert(result.getResult()));
|
||||
}
|
||||
}.open();
|
||||
|
||||
@@ -397,8 +397,9 @@ class JedisClusterSetCommands implements RedisSetCommands {
|
||||
protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
|
||||
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
ScanResult<byte[]> result = connection.getCluster().sscan(key, JedisConverters.toBytes(cursorId), params);
|
||||
return new ScanIteration<>(Long.parseLong(result.getCursor()), result.getResult());
|
||||
ScanResult<byte[]> result = connection.getCluster().sscan(key,
|
||||
JedisConverters.toBytes(Long.toUnsignedString(cursorId)), params);
|
||||
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()), result.getResult());
|
||||
}
|
||||
}.open();
|
||||
}
|
||||
|
||||
@@ -1084,8 +1084,8 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
|
||||
ScanResult<redis.clients.jedis.resps.Tuple> result = connection.getCluster().zscan(key,
|
||||
JedisConverters.toBytes(cursorId), params);
|
||||
return new ScanIteration<>(Long.valueOf(result.getCursor()),
|
||||
JedisConverters.toBytes(Long.toUnsignedString(cursorId)), params);
|
||||
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()),
|
||||
JedisConverters.tuplesToTuples().convert(result.getResult()));
|
||||
}
|
||||
}.open();
|
||||
|
||||
@@ -244,9 +244,10 @@ class JedisHashCommands implements RedisHashCommands {
|
||||
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
|
||||
ScanResult<Entry<byte[], byte[]>> result = connection.getJedis().hscan(key, JedisConverters.toBytes(cursorId),
|
||||
ScanResult<Entry<byte[], byte[]>> result = connection.getJedis().hscan(key,
|
||||
JedisConverters.toBytes(Long.toUnsignedString(cursorId)),
|
||||
params);
|
||||
return new ScanIteration<>(Long.valueOf(result.getCursor()), result.getResult());
|
||||
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()), result.getResult());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -165,12 +165,12 @@ class JedisKeyCommands implements RedisKeyCommands {
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
result = connection.getJedis().scan(Long.toString(cursorId).getBytes(), params, type);
|
||||
result = connection.getJedis().scan(Long.toUnsignedString(cursorId).getBytes(), params, type);
|
||||
} else {
|
||||
result = connection.getJedis().scan(Long.toString(cursorId).getBytes(), params);
|
||||
result = connection.getJedis().scan(Long.toUnsignedString(cursorId).getBytes(), params);
|
||||
}
|
||||
|
||||
return new ScanIteration<>(Long.parseLong(result.getCursor()), result.getResult());
|
||||
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()), result.getResult());
|
||||
}
|
||||
|
||||
protected void doClose() {
|
||||
|
||||
@@ -231,8 +231,9 @@ class JedisSetCommands implements RedisSetCommands {
|
||||
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
|
||||
ScanResult<byte[]> result = connection.getJedis().sscan(key, JedisConverters.toBytes(cursorId), params);
|
||||
return new ScanIteration<>(Long.valueOf(result.getCursor()), result.getResult());
|
||||
ScanResult<byte[]> result = connection.getJedis().sscan(key,
|
||||
JedisConverters.toBytes(Long.toUnsignedString(cursorId)), params);
|
||||
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()), result.getResult());
|
||||
}
|
||||
|
||||
protected void doClose() {
|
||||
|
||||
@@ -587,8 +587,8 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
ScanParams params = JedisConverters.toScanParams(options);
|
||||
|
||||
ScanResult<redis.clients.jedis.resps.Tuple> result = connection.getJedis().zscan(key,
|
||||
JedisConverters.toBytes(cursorId), params);
|
||||
return new ScanIteration<>(Long.valueOf(result.getCursor()),
|
||||
JedisConverters.toBytes(Long.toUnsignedString(cursorId)), params);
|
||||
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()),
|
||||
JedisConverters.tuplesToTuples().convert(result.getResult()));
|
||||
}
|
||||
|
||||
|
||||
@@ -1061,7 +1061,7 @@ public class LettuceConnection extends AbstractRedisConnection {
|
||||
}
|
||||
|
||||
io.lettuce.core.ScanCursor getScanCursor(long cursorId) {
|
||||
return io.lettuce.core.ScanCursor.of(Long.toString(cursorId));
|
||||
return io.lettuce.core.ScanCursor.of(Long.toUnsignedString(cursorId));
|
||||
}
|
||||
|
||||
private void validateCommandIfRunningInTransactionMode(ProtocolKeyword cmd, byte[]... args) {
|
||||
|
||||
@@ -235,7 +235,7 @@ class LettuceHashCommands implements RedisHashCommands {
|
||||
String nextCursorId = mapScanCursor.getCursor();
|
||||
|
||||
Map<byte[], byte[]> values = mapScanCursor.getMap();
|
||||
return new ScanIteration<>(Long.valueOf(nextCursorId), values.entrySet());
|
||||
return new ScanIteration<>(Long.parseUnsignedLong(nextCursorId), values.entrySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -77,7 +77,7 @@ abstract class LettuceScanCursor<T> extends ScanCursor<T> {
|
||||
}
|
||||
|
||||
private boolean isMatchingCursor(long cursorId) {
|
||||
return state != null && state.getCursor().equals(Long.toString(cursorId));
|
||||
return state != null && state.getCursor().equals(Long.toUnsignedString(cursorId));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +101,7 @@ abstract class LettuceScanCursor<T> extends ScanCursor<T> {
|
||||
|
||||
LettuceScanIteration(io.lettuce.core.ScanCursor cursor, Collection<T> items) {
|
||||
|
||||
super(Long.parseLong(cursor.getCursor()), items);
|
||||
super(Long.parseUnsignedLong(cursor.getCursor()), items);
|
||||
this.cursor = cursor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ class LettuceSetCommands implements RedisSetCommands {
|
||||
String nextCursorId = valueScanCursor.getCursor();
|
||||
|
||||
List<byte[]> values = connection.failsafeReadScanValues(valueScanCursor.getValues(), null);
|
||||
return new ScanIteration<>(Long.valueOf(nextCursorId), values);
|
||||
return new ScanIteration<>(Long.parseUnsignedLong(nextCursorId), values);
|
||||
}
|
||||
|
||||
protected void doClose() {
|
||||
|
||||
@@ -559,7 +559,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
List<ScoredValue<byte[]>> result = scoredValueScanCursor.getValues();
|
||||
|
||||
List<Tuple> values = connection.failsafeReadScanValues(result, LettuceConverters.scoredValuesToTupleList());
|
||||
return new ScanIteration<>(Long.valueOf(nextCursorId), values);
|
||||
return new ScanIteration<>(Long.parseUnsignedLong(nextCursorId), values);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user