Skip to content

Not working on parallel #23

@suguru03

Description

@suguru03

I started using the library and realized that it seems not working properly on concurrent requests.
I tested several scenarios, and it seems only to return the last command with the first result.

import { connect } from 'https://denopkg.com/keroxp/deno-redis/redis.ts';

const config = { hostname: '127.0.0.1', port: 6379 };
const keys = ['a', 'b', 'c'];
(async () => {
  const redis = await connect(config);
  for (const key of keys) {
    await redis.set(key, key);
  }
})();
// in series, it works fine
(async () => {
  const redis = await connect(config);
  for (const key of keys) {
    const val = await redis.get(key);
    console.log({ key, val });
  }
  /**
   * { key: "a", val: "a" }
   * { key: "b", val: "b" }
   * { key: "c", val: "c" }
   */
})();
// get a wrong result
(async () => {
  const redis = await connect(config);
  for (const key of keys) {
    redis.get(key).then(val => {
      console.log({ key, val });
    });
  }
  /**
   * wrong output and only one
   * { key: "c", val: "a" }
   */
})();
// no responses
(async () => {
  const redis = await connect(config);
  const values = await Promise.all(keys.map(key => redis.get(key)));
  console.log(values); // never reached
})();
// get a wrong result
(async () => {
  const redis = await connect(config);
  redis.get(keys[0]);
  const values = await redis.keys('*');
  console.log(values); // a
})();

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