method

RedisClient.scan

cursor: string | number
): Promise<[string, string[]]>;

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".

@param cursor

The cursor value (use "0" to start a new iteration)

@returns

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");
cursor: string | number,
match: 'MATCH',
pattern: string
): Promise<[string, string[]]>;

Incrementally iterate the keyspace with a pattern match

@param cursor

The cursor value (use "0" to start a new iteration)

@param match

The "MATCH" keyword

@param pattern

The pattern to match (supports glob-style patterns like "user:*")

@returns

Promise that resolves with a tuple [cursor, keys[]]

cursor: string | number,
count: 'COUNT',
hint: number
): Promise<[string, string[]]>;

Incrementally iterate the keyspace with a count hint

@param cursor

The cursor value (use "0" to start a new iteration)

@param count

The "COUNT" keyword

@param hint

The number of elements to return per call (hint only, not exact)

@returns

Promise that resolves with a tuple [cursor, keys[]]

cursor: string | number,
match: 'MATCH',
pattern: string,
count: 'COUNT',
hint: number
): Promise<[string, string[]]>;

Incrementally iterate the keyspace with pattern match and count hint

@param cursor

The cursor value (use "0" to start a new iteration)

@param match

The "MATCH" keyword

@param pattern

The pattern to match

@param count

The "COUNT" keyword

@param hint

The number of elements to return per call

@returns

Promise that resolves with a tuple [cursor, keys[]]

cursor: string | number,
...options: string | number[]
): Promise<[string, string[]]>;

Incrementally iterate the keyspace with options

@param cursor

The cursor value

@param options

Additional SCAN options (MATCH pattern, COUNT hint, etc.)

@returns

Promise that resolves with a tuple [cursor, keys[]]