method
RedisClient.scan
Incrementally iterate the keyspace
SCAN iterates the set of keys in the currently selected Redis database. It is a cursor-based iterator: each call returns an updated cursor to pass as the cursor argument in the next call.
An iteration starts when the cursor is set to "0", and terminates when the cursor returned by the server is "0".
The cursor value (use "0" to start a new iteration)
Promise that resolves with a tuple [cursor, keys[]] where cursor is the next cursor to use (or "0" if iteration is complete) and keys is an array of matching keys
// Basic scan - iterate all keys
let cursor = "0";
const allKeys: string[] = [];
do {
const [nextCursor, keys] = await redis.scan(cursor);
allKeys.push(...keys);
cursor = nextCursor;
} while (cursor !== "0");Incrementally iterate the keyspace with a pattern match
The cursor value (use "0" to start a new iteration)
The "MATCH" keyword
The pattern to match (supports glob-style patterns like "user:*")
Promise that resolves with a tuple [cursor, keys[]]
Incrementally iterate the keyspace with a count hint
The cursor value (use "0" to start a new iteration)
The "COUNT" keyword
The number of elements to return per call (hint only, not exact)
Promise that resolves with a tuple [cursor, keys[]]
Incrementally iterate the keyspace with pattern match and count hint
The cursor value (use "0" to start a new iteration)
The "MATCH" keyword
The pattern to match
The "COUNT" keyword
The number of elements to return per call
Promise that resolves with a tuple [cursor, keys[]]
Incrementally iterate the keyspace with options
The cursor value
Additional SCAN options (MATCH pattern, COUNT hint, etc.)
Promise that resolves with a tuple [cursor, keys[]]