NODEID parameter to the end of the command to scan only the specified shard node.-ERR invalid cursor(master node idx out of range)NODEID parameter to the end of the SCAN command to scan only the data of a specified shard node, which is suitable for shard-specific troubleshooting or shard-level processing scenarios.f2f3c387b9fab0e67af02039845c60278b13bed0, run the following command:scan 0 MATCH * COUNT 100 f2f3c387b9fab0e67af02039****************
Node Management page in the console or obtain it by running the cluster nodes command.NODEID parameter, SCAN traverses data across all shards in the cluster, which requires Proxy 5.8.9 or later. Iteration starts from cursor 0 and ends when the cursor returns to 0, indicating that the traversal is complete.package com.example.service.impl;public class RedisServiceImpl implements RedisService {// Maximum number of scan retriesprivate static final int MAX_RETRIES = 3;private final RedisConnectionFactory connectionFactory;@Overridepublic void scanKeys(String pattern, int count) {try (Jedis jedis = connectionFactory.getConnection()) {int retryCount = 0;boolean scanCompleted = false;// Catch errors during the scan process. If an error occurs, restart the scan from 0.while (!scanCompleted && retryCount <= MAX_RETRIES) {String cursor = ScanParams.SCAN_POINTER_START;ScanParams scanParams = new ScanParams();scanParams.count(count);scanParams.match(pattern);try {while (true) {ScanResult<String> scanResult = jedis.scan(cursor, scanParams);List<String> keys = scanResult.getResult();if (!keys.isEmpty()) {processKeysWithBusinessLogic(keys); // Business processing}cursor = scanResult.getCursor();// The scan is complete when the cursor is "0".if (cursor.equals(ScanParams.SCAN_POINTER_START)) {scanCompleted = true;break;}}} catch (Exception e) {retryCount++;// The maximum number of retries is exceeded, and the retry is terminated.if (retryCount > MAX_RETRIES) {throw new RuntimeException("Maximum retry count reached, scan failed", e);}}}}}}
Parameter / Logic | Description |
MAX_RETRIES | Maximum number of SCAN retries. Example: 3. Adjust this value based on business requirements. |
cursor | The cursor. Each scan round starts from the initial position 0 (ScanParams.SCAN_POINTER_START), and the cursor returning to 0 indicates that the traversal is complete. |
scanParams.match(pattern) | Matches keys by pattern. |
scanParams.count(count) | Hint on the number of elements returned in each iteration. |
Exception catching | After exceptions such as cursor invalidation are caught, increment the retry count by 1 and rescan from cursor 0; if MAX_RETRIES is exceeded, throw an exception to terminate and avoid an infinite loop. |
0 and scanCompleted is true, indicating that the traversal is complete without entering an infinite loop.invalid cursor (master node idx out of range)?0, and restart the scan. Do not ignore the error and continue iterating with the original cursor, as this will cause an infinite loop.0; if the retry limit is exceeded, terminate the scan and throw an exception.NODEID parameter to the end of the SCAN command. For the specific command syntax, refer to the actual support of the instance.Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback