Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working on parallel #23

Closed
suguru03 opened this issue Oct 18, 2019 · 2 comments
Closed

Not working on parallel #23

suguru03 opened this issue Oct 18, 2019 · 2 comments

Comments

@suguru03
Copy link
Collaborator

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
})();
@keroxp
Copy link
Collaborator

keroxp commented Oct 18, 2019

@suguru03 Thank you for reporting. Fixed and hope your code works fine!

@suguru03
Copy link
Collaborator Author

Thanks for promptly fixing the issue! It works! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants