GeezerVison is showing github.com — scanIteration on a cluster with replicas returns every key more than once · Issue #4797 · redis/jedis
scanIteration on a cluster with replicas returns every key more than once #4797
Description
Expected behavior
RedisClusterClient.scanIteration(...) returns each key in the cluster once.
Actual behavior
On a cluster with replicas, each key is returned once by its primary and once more by every replica of that primary. With one replica per shard, a cluster holding 100 keys yields 200 keys from scanIteration.
JedisCommandIterationBase builds its node list from ConnectionProvider.getConnectionMap(). For ClusterConnectionProvider that map holds every known node, replicas included, so SCAN runs on replicas as well as primaries. ftSearchIteration and ftAggregateIteration use the same base class.
The existing cluster tests do not catch this because they collect the result into a Set.
Steps to reproduce:
-
Start a cluster with 3 primaries and 1 replica each (for example redis-cli --cluster create 127.0.0.1:37000 ... 127.0.0.1:37005 --cluster-replicas 1).
-
Run:
try (RedisClusterClient c = RedisClusterClient.builder()
.nodes(Collections.singleton(new HostAndPort("127.0.0.1", 37000))).build()) {
for (int i = 0; i < 100; i++) c.set("k" + i, "v");
List<String> keys = new ArrayList<>();
c.scanIteration(10, "*").collect(keys);
System.out.println(keys.size() + " " + new HashSet<>(keys).size());
}
-
The output is 200 100. The expected output is 100 100.
Redis / Jedis Configuration
Jedis version:
8.1.0-SNAPSHOT (master at 57af871)
Redis version:
8.2
Java version:
Temurin 8
Activity
Rainmemery commented on Oct 19, 2026
added 2 commits that reference this issue
on Oct 19, 2026This issue will close once commit 6e07a6e is merged into the 'master' branch.6e07a6e This issue will close once commit d46895c is merged into the 'master' branch.d46895c ggivo commented on Oct 20, 2026
Fixed by #4798 (7106a66), shipping in 8.1: scanIteration, ftSearchIteration and ftAggregateIteration now visit primary nodes only, so each key is returned once. #4802 duplicates that fix and is closed.
Metadata
Metadata
Development
No branches or pull requestsIssue actions