Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Ensure complete retrieval of keys when using Redis SCAN command. #5

@ofluffydev

Description

@ofluffydev
          **Ensure complete retrieval of keys when using Redis SCAN command.**

The current usage of redis.scan may not retrieve all matching keys, as SCAN is a cursor-based iterator that requires looping until the cursor returns zero. The scan command fetches a subset of keys per call and provides a cursor for the next set.

Consider modifying the code to iterate over the cursor to collect all matching keys:

let cursor = 0;
const hashKeys: string[] = [];

do {
  const reply = await redis.scan(cursor, { MATCH: 'hash:*' });
  cursor = reply.cursor;
  hashKeys.push(...reply.keys);
} while (cursor !== 0);

const hashes = hashKeys.map((hash) => hash.substring(5));

This ensures that all matching keys are retrieved. Alternatively, if the number of keys is expected to be small, you might consider organizing your data differently in Redis to allow more efficient retrieval.

Originally posted by @coderabbitai[bot] in #1 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions