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:
Mark Paluch
2023-12-12 15:24:01 +01:00
committed by Christoph Strobl
parent 966dc05704
commit b9f2e4c509
13 changed files with 27 additions and 23 deletions

View File

@@ -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();
}

View File

@@ -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();

View File

@@ -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();
}

View File

@@ -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();

View File

@@ -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

View File

@@ -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() {

View File

@@ -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() {

View File

@@ -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()));
}

View File

@@ -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) {

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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() {

View File

@@ -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