stipsan / ioredis-mock

Emulates ioredis by performing all operations in-memory.
MIT License
333 stars 125 forks source link

lpop has different behaviour than redis #1316

Open ytkimirti opened 1 year ago

ytkimirti commented 1 year ago

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