Skip to content

Commit

Permalink
Use Long.parseUnsignedLong/toUnsignedString for SCAN cursor id parsing.
Browse files Browse the repository at this point in the history
Redis uses an unsigned 64bit value for its cursor id which is now captured via parseUnsignedLong.

Closes: #2796
  • Loading branch information
mp911de authored and christophstrobl committed Dec 13, 2023
1 parent 966dc05 commit b9f2e4c
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,10 @@ protected ScanIteration<Entry<byte[], byte[]>> doScan(long cursorId, ScanOptions

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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ Cursor<byte[]> scan(RedisClusterNode node, ScanOptions options) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,9 @@ public Cursor<byte[]> sScan(byte[] key, ScanOptions options) {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,8 @@ protected ScanIteration<Tuple> doScan(long cursorId, ScanOptions options) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ protected ScanIteration<Entry<byte[], byte[]>> doScan(byte[] key, long cursorId,

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
}

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ protected ScanIteration<byte[]> doScan(byte[] key, long cursorId, ScanOptions op

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ protected ScanIteration<Tuple> doScan(byte[] key, long cursorId, ScanOptions opt
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()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ private void potentiallySelectDatabase(int dbIndex) {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ protected ScanIteration<Entry<byte[], byte[]>> doScan(byte[] key, long cursorId,
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private ScanIteration<T> scanAndProcessState(io.lettuce.core.ScanCursor scanCurs
}

private boolean isMatchingCursor(long cursorId) {
return state != null && state.getCursor().equals(Long.toString(cursorId));
return state != null && state.getCursor().equals(Long.toUnsignedString(cursorId));
}

/**
Expand All @@ -101,7 +101,7 @@ static class LettuceScanIteration<T> extends ScanIteration<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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ protected ScanIteration<byte[]> doScan(byte[] key, long cursorId, ScanOptions op
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ protected ScanIteration<Tuple> doScan(byte[] key, long cursorId, ScanOptions opt
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
Expand Down

0 comments on commit b9f2e4c

Please sign in to comment.