scan_keys
Scan Redis database keys safely in chunks using the SCAN command. Ideal for large datasets, it provides partial results per iteration, allowing non-blocking production use. Use a cursor to continue or retrieve all matching keys with scan_all_keys().
Instructions
Scan keys in the Redis database using the SCAN command (non-blocking, production-safe).
⚠️ IMPORTANT: This returns PARTIAL results from one iteration. Use scan_all_keys() to get ALL matching keys, or call this function multiple times with the returned cursor until cursor becomes 0.
The SCAN command iterates through the keyspace in small chunks, making it safe to use on large databases without blocking other operations.
Args: pattern: Pattern to match keys against (default is "" for all keys). Common patterns: "user:", "cache:", ":123", etc. count: Hint for the number of keys to return per iteration (default 100). Redis may return more or fewer keys than this hint. cursor: The cursor position to start scanning from (0 to start from beginning). To continue scanning, use the cursor value returned from previous call.
Returns: A dictionary containing: - 'cursor': Next cursor position (0 means scan is complete) - 'keys': List of keys found in this iteration (PARTIAL RESULTS) - 'total_scanned': Number of keys returned in this batch - 'scan_complete': Boolean indicating if scan is finished Or an error message if something goes wrong.
Example usage: First call: scan_keys("user:") -> returns cursor=1234, keys=[...], scan_complete=False Next call: scan_keys("user:", cursor=1234) -> continues from where it left off Final call: returns cursor=0, scan_complete=True when done
Input Schema
Name | Required | Description | Default |
---|---|---|---|
count | No | ||
cursor | No | ||
pattern | No | * |