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

lpop has different behaviour than redis #1316

Open
ytkimirti opened this issue Sep 5, 2023 · 0 comments · May be fixed by #1330
Open

lpop has different behaviour than redis #1316

ytkimirti opened this issue Sep 5, 2023 · 0 comments · May be fixed by #1330

Comments

@ytkimirti
Copy link

ytkimirti commented Sep 5, 2023

When supplying a second argument to lpop in redis it returns that amount of elements as a list. ioredis-mock returns a single element no matter what.

Code example:

const Redis = require("ioredis");
const RedisMock = require("ioredis-mock");
const assert = require("assert");

const redis = new Redis();
const redisMock = new RedisMock();

const testEquality = async () => {
  await redis.rpush("key", 1);
  await redis.rpush("key", 2);
  await redis.rpush("key", 3);
  await redisMock.rpush("key", 1);
  await redisMock.rpush("key", 2);
  await redisMock.rpush("key", 3);

  const pop = await redis.lpop("key", 3);
  const popMock = await redisMock.lpop("key", 3);

  await redis.flushall();
  await redisMock.flushall();
  await redis.quit();
  await redisMock.quit();

  assert(
    pop === popMock,
    `expected <${popMock.constructor.name}>(${popMock}) to equal <${pop.constructor.name}>(${pop})`
  );
  return "Success";
};

testEquality().then(console.log).catch(console.error);

Output:

AssertionError [ERR_ASSERTION]: expected <String>(1) to equal <Array>(1,2,3)
    at testEquality (/Users/kimirti/tmp/ioredis-mock/index.js:24:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

Found a similar issue #431

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

Successfully merging a pull request may close this issue.

1 participant