Skip to content

Commit 6e0f30b

Browse files
mp911dechristophstrobl
authored andcommitted
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
1 parent c64e6d0 commit 6e0f30b

13 files changed

+27
-23
lines changed

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterHashCommands.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,10 @@ protected ScanIteration<Entry<byte[], byte[]>> doScan(long cursorId, ScanOptions
279279

280280
ScanParams params = JedisConverters.toScanParams(options);
281281

282-
ScanResult<Entry<byte[], byte[]>> result = connection.getCluster().hscan(key, JedisConverters.toBytes(cursorId),
282+
ScanResult<Entry<byte[], byte[]>> result = connection.getCluster().hscan(key,
283+
JedisConverters.toBytes(Long.toUnsignedString(cursorId)),
283284
params);
284-
return new ScanIteration<>(Long.valueOf(result.getCursor()), result.getResult());
285+
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()), result.getResult());
285286
}
286287
}.open();
287288
}

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterKeyCommands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ Cursor<byte[]> scan(RedisClusterNode node, ScanOptions options) {
180180
protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
181181

182182
ScanParams params = JedisConverters.toScanParams(options);
183-
ScanResult<String> result = client.scan(Long.toString(cursorId), params);
184-
return new ScanIteration<>(Long.valueOf(result.getCursor()),
183+
ScanResult<String> result = client.scan(Long.toUnsignedString(cursorId), params);
184+
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()),
185185
JedisConverters.stringListToByteList().convert(result.getResult()));
186186
}
187187
}.open();

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterSetCommands.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,9 @@ public Cursor<byte[]> sScan(byte[] key, ScanOptions options) {
397397
protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
398398

399399
ScanParams params = JedisConverters.toScanParams(options);
400-
ScanResult<byte[]> result = connection.getCluster().sscan(key, JedisConverters.toBytes(cursorId), params);
401-
return new ScanIteration<>(Long.parseLong(result.getCursor()), result.getResult());
400+
ScanResult<byte[]> result = connection.getCluster().sscan(key,
401+
JedisConverters.toBytes(Long.toUnsignedString(cursorId)), params);
402+
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()), result.getResult());
402403
}
403404
}.open();
404405
}

src/main/java/org/springframework/data/redis/connection/jedis/JedisClusterZSetCommands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,8 +1084,8 @@ protected ScanIteration<Tuple> doScan(long cursorId, ScanOptions options) {
10841084
ScanParams params = JedisConverters.toScanParams(options);
10851085

10861086
ScanResult<redis.clients.jedis.resps.Tuple> result = connection.getCluster().zscan(key,
1087-
JedisConverters.toBytes(cursorId), params);
1088-
return new ScanIteration<>(Long.valueOf(result.getCursor()),
1087+
JedisConverters.toBytes(Long.toUnsignedString(cursorId)), params);
1088+
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()),
10891089
JedisConverters.tuplesToTuples().convert(result.getResult()));
10901090
}
10911091
}.open();

src/main/java/org/springframework/data/redis/connection/jedis/JedisHashCommands.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,10 @@ protected ScanIteration<Entry<byte[], byte[]>> doScan(byte[] key, long cursorId,
244244

245245
ScanParams params = JedisConverters.toScanParams(options);
246246

247-
ScanResult<Entry<byte[], byte[]>> result = connection.getJedis().hscan(key, JedisConverters.toBytes(cursorId),
247+
ScanResult<Entry<byte[], byte[]>> result = connection.getJedis().hscan(key,
248+
JedisConverters.toBytes(Long.toUnsignedString(cursorId)),
248249
params);
249-
return new ScanIteration<>(Long.valueOf(result.getCursor()), result.getResult());
250+
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()), result.getResult());
250251
}
251252

252253
@Override

src/main/java/org/springframework/data/redis/connection/jedis/JedisKeyCommands.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ protected ScanIteration<byte[]> doScan(long cursorId, ScanOptions options) {
165165
}
166166

167167
if (type != null) {
168-
result = connection.getJedis().scan(Long.toString(cursorId).getBytes(), params, type);
168+
result = connection.getJedis().scan(Long.toUnsignedString(cursorId).getBytes(), params, type);
169169
} else {
170-
result = connection.getJedis().scan(Long.toString(cursorId).getBytes(), params);
170+
result = connection.getJedis().scan(Long.toUnsignedString(cursorId).getBytes(), params);
171171
}
172172

173-
return new ScanIteration<>(Long.parseLong(result.getCursor()), result.getResult());
173+
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()), result.getResult());
174174
}
175175

176176
protected void doClose() {

src/main/java/org/springframework/data/redis/connection/jedis/JedisSetCommands.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,9 @@ protected ScanIteration<byte[]> doScan(byte[] key, long cursorId, ScanOptions op
231231

232232
ScanParams params = JedisConverters.toScanParams(options);
233233

234-
ScanResult<byte[]> result = connection.getJedis().sscan(key, JedisConverters.toBytes(cursorId), params);
235-
return new ScanIteration<>(Long.valueOf(result.getCursor()), result.getResult());
234+
ScanResult<byte[]> result = connection.getJedis().sscan(key,
235+
JedisConverters.toBytes(Long.toUnsignedString(cursorId)), params);
236+
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()), result.getResult());
236237
}
237238

238239
protected void doClose() {

src/main/java/org/springframework/data/redis/connection/jedis/JedisZSetCommands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,8 @@ protected ScanIteration<Tuple> doScan(byte[] key, long cursorId, ScanOptions opt
587587
ScanParams params = JedisConverters.toScanParams(options);
588588

589589
ScanResult<redis.clients.jedis.resps.Tuple> result = connection.getJedis().zscan(key,
590-
JedisConverters.toBytes(cursorId), params);
591-
return new ScanIteration<>(Long.valueOf(result.getCursor()),
590+
JedisConverters.toBytes(Long.toUnsignedString(cursorId)), params);
591+
return new ScanIteration<>(Long.parseUnsignedLong(result.getCursor()),
592592
JedisConverters.tuplesToTuples().convert(result.getResult()));
593593
}
594594

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ private void potentiallySelectDatabase(int dbIndex) {
10611061
}
10621062

10631063
io.lettuce.core.ScanCursor getScanCursor(long cursorId) {
1064-
return io.lettuce.core.ScanCursor.of(Long.toString(cursorId));
1064+
return io.lettuce.core.ScanCursor.of(Long.toUnsignedString(cursorId));
10651065
}
10661066

10671067
private void validateCommandIfRunningInTransactionMode(ProtocolKeyword cmd, byte[]... args) {

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceHashCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ protected ScanIteration<Entry<byte[], byte[]>> doScan(byte[] key, long cursorId,
235235
String nextCursorId = mapScanCursor.getCursor();
236236

237237
Map<byte[], byte[]> values = mapScanCursor.getMap();
238-
return new ScanIteration<>(Long.valueOf(nextCursorId), values.entrySet());
238+
return new ScanIteration<>(Long.parseUnsignedLong(nextCursorId), values.entrySet());
239239
}
240240

241241
@Override

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceScanCursor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private ScanIteration<T> scanAndProcessState(io.lettuce.core.ScanCursor scanCurs
7777
}
7878

7979
private boolean isMatchingCursor(long cursorId) {
80-
return state != null && state.getCursor().equals(Long.toString(cursorId));
80+
return state != null && state.getCursor().equals(Long.toUnsignedString(cursorId));
8181
}
8282

8383
/**
@@ -101,7 +101,7 @@ static class LettuceScanIteration<T> extends ScanIteration<T> {
101101

102102
LettuceScanIteration(io.lettuce.core.ScanCursor cursor, Collection<T> items) {
103103

104-
super(Long.parseLong(cursor.getCursor()), items);
104+
super(Long.parseUnsignedLong(cursor.getCursor()), items);
105105
this.cursor = cursor;
106106
}
107107
}

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceSetCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ protected ScanIteration<byte[]> doScan(byte[] key, long cursorId, ScanOptions op
232232
String nextCursorId = valueScanCursor.getCursor();
233233

234234
List<byte[]> values = connection.failsafeReadScanValues(valueScanCursor.getValues(), null);
235-
return new ScanIteration<>(Long.valueOf(nextCursorId), values);
235+
return new ScanIteration<>(Long.parseUnsignedLong(nextCursorId), values);
236236
}
237237

238238
protected void doClose() {

src/main/java/org/springframework/data/redis/connection/lettuce/LettuceZSetCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ protected ScanIteration<Tuple> doScan(byte[] key, long cursorId, ScanOptions opt
559559
List<ScoredValue<byte[]>> result = scoredValueScanCursor.getValues();
560560

561561
List<Tuple> values = connection.failsafeReadScanValues(result, LettuceConverters.scoredValuesToTupleList());
562-
return new ScanIteration<>(Long.valueOf(nextCursorId), values);
562+
return new ScanIteration<>(Long.parseUnsignedLong(nextCursorId), values);
563563
}
564564

565565
@Override

0 commit comments

Comments
 (0)