From 513e1b65bc39e0753411ff9186d8e6bfc5998a3b Mon Sep 17 00:00:00 2001 From: Vlastimil Kotas Date: Mon, 11 Nov 2024 18:17:07 +0100 Subject: [PATCH] use CursorId in ScanIteration to avoid long overflow - Spring Data 3.3 deprecated `long cursorId` in favor of String-backed `CursorId` object to avoid `NumberFormatException` when then cursor ID is bigger than max long - more info: https://github.com/spring-projects/spring-data-redis/issues/2796 Signed-off-by: Vlastimil Kotas --- .../data/connection/RedissonClusterConnection.java | 8 ++++---- .../spring/data/connection/RedissonConnection.java | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/redisson-spring-data/redisson-spring-data-33/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java b/redisson-spring-data/redisson-spring-data-33/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java index 32e02fc26..f1a2fbd4d 100644 --- a/redisson-spring-data/redisson-spring-data-33/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java +++ b/redisson-spring-data/redisson-spring-data-33/src/main/java/org/redisson/spring/data/connection/RedissonClusterConnection.java @@ -389,7 +389,7 @@ public class RedissonClusterConnection extends RedissonConnection implements Red private RedisClient client = getEntry(node); @Override - protected ScanIteration doScan(long cursorId, ScanOptions options) { + protected ScanIteration doScan(CursorId cursorId, ScanOptions options) { if (isQueueing() || isPipelined()) { throw new UnsupportedOperationException("'SSCAN' cannot be called in pipeline / transaction mode."); } @@ -399,7 +399,7 @@ public class RedissonClusterConnection extends RedissonConnection implements Red } List args = new ArrayList(); - args.add(Long.toUnsignedString(cursorId)); + args.add(cursorId); if (options.getPattern() != null) { args.add("MATCH"); args.add(options.getPattern()); @@ -413,11 +413,11 @@ public class RedissonClusterConnection extends RedissonConnection implements Red ListScanResult res = syncFuture(f); String pos = res.getPos(); client = res.getRedisClient(); - if ("0".equals(pos)) { + if (CursorId.isInitial(pos)) { client = null; } - return new ScanIteration(Long.parseUnsignedLong(pos), res.getValues()); + return new ScanIteration(CursorId.of(pos), res.getValues()); } }.open(); } diff --git a/redisson-spring-data/redisson-spring-data-33/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java b/redisson-spring-data/redisson-spring-data-33/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java index 112598ebc..d1eb93be9 100644 --- a/redisson-spring-data/redisson-spring-data-33/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java +++ b/redisson-spring-data/redisson-spring-data-33/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java @@ -252,14 +252,14 @@ public class RedissonConnection extends AbstractRedisConnection { @Override public Cursor scan(ScanOptions options) { - return new ScanCursor(0, options) { + return new ScanCursor(Cursor.CursorId.initial(), options) { private RedisClient client; private Iterator entries = redisson.getConnectionManager().getEntrySet().iterator(); private MasterSlaveEntry entry = entries.next(); @Override - protected ScanIteration doScan(long cursorId, ScanOptions options) { + protected ScanIteration doScan(CursorId cursorId, ScanOptions options) { if (isQueueing() || isPipelined()) { throw new UnsupportedOperationException("'SSCAN' cannot be called in pipeline / transaction mode."); } @@ -269,10 +269,10 @@ public class RedissonConnection extends AbstractRedisConnection { } List args = new ArrayList(); - if (cursorId == 101010101010101010L) { - cursorId = 0; + if (CursorId.of("101010101010101010").equals(cursorId)) { + cursorId = CursorId.initial(); } - args.add(Long.toUnsignedString(cursorId)); + args.add(cursorId); if (options.getPattern() != null) { args.add("MATCH"); args.add(options.getPattern()); @@ -286,7 +286,7 @@ public class RedissonConnection extends AbstractRedisConnection { ListScanResult res = syncFuture(f); String pos = res.getPos(); client = res.getRedisClient(); - if ("0".equals(pos)) { + if (CursorId.isInitial(pos)) { if (entries.hasNext()) { pos = "101010101010101010"; entry = entries.next(); @@ -296,7 +296,7 @@ public class RedissonConnection extends AbstractRedisConnection { } } - return new ScanIteration(Long.parseUnsignedLong(pos), res.getValues()); + return new ScanIteration(CursorId.of(pos), res.getValues()); } }.open(); }