From 347e0dd37194005740e0b3076314c80902eb69d1 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Tue, 19 Apr 2022 09:12:04 +0300 Subject: [PATCH] Fixed - Spring Data Redis module. Scan In cluster mode, other nodes cannot be scanned #4238 --- .../data/connection/RedissonConnection.java | 1 + .../data/connection/RedissonConnection.java | 1 + .../data/connection/RedissonConnection.java | 1 + .../data/connection/RedissonConnection.java | 1 + .../data/connection/RedissonConnection.java | 1 + .../data/connection/RedissonConnection.java | 1 + .../data/connection/RedissonConnection.java | 1 + .../data/connection/RedissonConnection.java | 1 + .../data/connection/RedissonConnection.java | 1 + .../data/connection/RedissonConnection.java | 1 + .../RedissonClusterConnectionTest.java | 18 ++++++++++++++++++ 11 files changed, 28 insertions(+) diff --git a/redisson-spring-data/redisson-spring-data-16/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java b/redisson-spring-data/redisson-spring-data-16/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java index 2e638a660..f4533ace0 100644 --- a/redisson-spring-data/redisson-spring-data-16/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java +++ b/redisson-spring-data/redisson-spring-data-16/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java @@ -278,6 +278,7 @@ public class RedissonConnection extends AbstractRedisConnection { if (entries.hasNext()) { pos = -1; entry = entries.next(); + client = null; } else { entry = null; } diff --git a/redisson-spring-data/redisson-spring-data-17/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java b/redisson-spring-data/redisson-spring-data-17/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java index 1da911751..62af8de09 100644 --- a/redisson-spring-data/redisson-spring-data-17/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java +++ b/redisson-spring-data/redisson-spring-data-17/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java @@ -297,6 +297,7 @@ public class RedissonConnection extends AbstractRedisConnection { if (entries.hasNext()) { pos = -1; entry = entries.next(); + client = null; } else { entry = null; } diff --git a/redisson-spring-data/redisson-spring-data-18/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java b/redisson-spring-data/redisson-spring-data-18/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java index bdd592c8f..4230eefdf 100644 --- a/redisson-spring-data/redisson-spring-data-18/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java +++ b/redisson-spring-data/redisson-spring-data-18/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java @@ -300,6 +300,7 @@ public class RedissonConnection extends AbstractRedisConnection { if (entries.hasNext()) { pos = -1; entry = entries.next(); + client = null; } else { entry = null; } diff --git a/redisson-spring-data/redisson-spring-data-20/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java b/redisson-spring-data/redisson-spring-data-20/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java index 57793368b..11b98ad89 100644 --- a/redisson-spring-data/redisson-spring-data-20/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java +++ b/redisson-spring-data/redisson-spring-data-20/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java @@ -282,6 +282,7 @@ public class RedissonConnection extends AbstractRedisConnection { if (entries.hasNext()) { pos = -1; entry = entries.next(); + client = null; } else { entry = null; } diff --git a/redisson-spring-data/redisson-spring-data-21/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java b/redisson-spring-data/redisson-spring-data-21/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java index db5489b51..eea9e3ad2 100644 --- a/redisson-spring-data/redisson-spring-data-21/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java +++ b/redisson-spring-data/redisson-spring-data-21/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java @@ -280,6 +280,7 @@ public class RedissonConnection extends AbstractRedisConnection { if (entries.hasNext()) { pos = -1; entry = entries.next(); + client = null; } else { entry = null; } diff --git a/redisson-spring-data/redisson-spring-data-22/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java b/redisson-spring-data/redisson-spring-data-22/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java index 76841ef5c..26372237f 100644 --- a/redisson-spring-data/redisson-spring-data-22/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java +++ b/redisson-spring-data/redisson-spring-data-22/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java @@ -280,6 +280,7 @@ public class RedissonConnection extends AbstractRedisConnection { if (entries.hasNext()) { pos = -1; entry = entries.next(); + client = null; } else { entry = null; } diff --git a/redisson-spring-data/redisson-spring-data-23/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java b/redisson-spring-data/redisson-spring-data-23/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java index 7b8831167..bae18258e 100644 --- a/redisson-spring-data/redisson-spring-data-23/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java +++ b/redisson-spring-data/redisson-spring-data-23/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java @@ -280,6 +280,7 @@ public class RedissonConnection extends AbstractRedisConnection { if (entries.hasNext()) { pos = -1; entry = entries.next(); + client = null; } else { entry = null; } diff --git a/redisson-spring-data/redisson-spring-data-24/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java b/redisson-spring-data/redisson-spring-data-24/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java index 2ad31664a..e2d40c5f9 100644 --- a/redisson-spring-data/redisson-spring-data-24/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java +++ b/redisson-spring-data/redisson-spring-data-24/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java @@ -280,6 +280,7 @@ public class RedissonConnection extends AbstractRedisConnection { if (entries.hasNext()) { pos = -1; entry = entries.next(); + client = null; } else { entry = null; } diff --git a/redisson-spring-data/redisson-spring-data-25/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java b/redisson-spring-data/redisson-spring-data-25/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java index 1c628c856..bd6878b78 100644 --- a/redisson-spring-data/redisson-spring-data-25/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java +++ b/redisson-spring-data/redisson-spring-data-25/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java @@ -280,6 +280,7 @@ public class RedissonConnection extends AbstractRedisConnection { if (entries.hasNext()) { pos = -1; entry = entries.next(); + client = null; } else { entry = null; } diff --git a/redisson-spring-data/redisson-spring-data-26/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java b/redisson-spring-data/redisson-spring-data-26/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java index 1c628c856..bd6878b78 100644 --- a/redisson-spring-data/redisson-spring-data-26/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java +++ b/redisson-spring-data/redisson-spring-data-26/src/main/java/org/redisson/spring/data/connection/RedissonConnection.java @@ -280,6 +280,7 @@ public class RedissonConnection extends AbstractRedisConnection { if (entries.hasNext()) { pos = -1; entry = entries.next(); + client = null; } else { entry = null; } diff --git a/redisson-spring-data/redisson-spring-data-26/src/test/java/org/redisson/spring/data/connection/RedissonClusterConnectionTest.java b/redisson-spring-data/redisson-spring-data-26/src/test/java/org/redisson/spring/data/connection/RedissonClusterConnectionTest.java index 7d389f86e..2a864ec1e 100644 --- a/redisson-spring-data/redisson-spring-data-26/src/test/java/org/redisson/spring/data/connection/RedissonClusterConnectionTest.java +++ b/redisson-spring-data/redisson-spring-data-26/src/test/java/org/redisson/spring/data/connection/RedissonClusterConnectionTest.java @@ -17,9 +17,12 @@ import org.springframework.data.redis.connection.ClusterInfo; import org.springframework.data.redis.connection.RedisClusterNode; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisNode.NodeType; +import org.springframework.data.redis.core.Cursor; +import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.core.types.RedisClientInfo; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.*; import static org.assertj.core.api.Assertions.assertThat; @@ -73,6 +76,21 @@ public class RedissonClusterConnectionTest { assertThat(connection.del(keys.toArray(new byte[0][]))).isEqualTo(10); } + @Test + public void testScan() { + for (int i = 0; i < 1000; i++) { + connection.set(("" + i).getBytes(StandardCharsets.UTF_8), ("" + i).getBytes(StandardCharsets.UTF_8)); + } + + Cursor b = connection.scan(ScanOptions.scanOptions().build()); + int counter = 0; + while (b.hasNext()) { + b.next(); + counter++; + } + assertThat(counter).isEqualTo(1000); + } + @Test public void testMSet() { Map map = new HashMap<>();