Skip to content

Concurrency issues with ioredis #1983

@robin202205

Description

@robin202205

Most of the time, this code gets stuck at Promise.all. Does get not support concurrency? How to solve this?

import { Redis } from 'ioredis';
import dotenv from 'dotenv';

dotenv.config();

const main = async () => {
  const keys = [
         xxxxxxxxxxxx,
         xxxxxxxxxxxx
         xxxxxxxxxxxx
         xxxxxxxxxxxx
         xxxxxxxxxxxx
  ];
  
  const client = new Redis(process.env.REDIS_RO_URL as string);
  
  const values = await Promise.all(
    keys.map(async (key) => {
      console.log(`key: ${key}, client status: ${client?.status}`);
      console.log(`key: ${key}, fetching cache  ${JSON.stringify(client?.commandQueue)}`);
      const value = await client.get(key);
      console.log(`key: ${key}, fetched cache value: ${value}`);
      return value;
    }),
  );
  
  console.log(`fetched cache values: ${JSON.stringify(values)}`);
  console.log('fetched cache values completed');
  
  client.disconnect();
  
  process.exit(0);
}

main();

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