Skip to content

Undefined results when using ReadFrom with SCAN family commands #3287

@Dishant18

Description

@Dishant18

Bug Report

Current Behavior

We have observed that when using the ReadFrom setting with SCAN family of commands, the continuation requests (with cursor) is not guaranteed to go to the same node as the first request. Due to this behaviour, the results of SCAN family requests are undefined.

We have a master-replica Redis setup with sentinel-based discovery.

Input Code

Input Code
RedisURI redisURI = RedisURI.Builder.sentinel("sentinel-host").build();
RedisClient redisClient = RedisClient.create(redisURI);

StatefulRedisMasterReplicaConnection<byte[], byte[]> conn = MasterReplica.connect(redisClient, ByteArrayCodec.INSTANCE, redisURI);
conn.setReadFrom(ReadFrom.ANY);

byte[] key = getKey();
ScanArgs scanArgs = ScanArgs.Builder.limit(256);
ScanCursor cursor = ScanCursor.INITIAL;
MapScanCursor<byte[], byte[]> resp;
do {
            resp = conn.sync().hscan(key, cursor, scanArgs);
            cursor = ScanCursor.of(hscan.getCursor());
            // Convert and add the results to a map
} while (!resp.isFinished());

Expected behavior/code

SCAN family continuation requests need to be sticky to a Redis Node. When it is used in conjunction with ReadFrom, on every continuation request - a new node can be chosen - which seems like a bug.

Environment

  • Lettuce version(s): 6.4.0.RELEASE
  • Redis version: 7+

Additional Context

The same support is present for ClusterScanCursor. It maintains a nodeId and routes the next command to the same node. Any reason for not adding this in Master-replica setup?

Metadata

Metadata

Assignees

No one assigned

    Labels

    size: medium2 to 4 development weeksstatus: help-wantedAn issue that a contributor can help us withstatus: mre-availableMinimal Reproducible Example is available

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions