stipsan / ioredis-mock

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

rpoplpush should rotate the list when source and destination are the same #1320

Closed mgrunberg closed 11 months ago

mgrunberg commented 11 months ago

When same source and destination are provided rpoplpush should rotate the list. Instead, it is prepending the last element.

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("list", 1);
  await redis.rpush("list", 2);
  await redis.rpush("list", 3);
  await redisMock.rpush("list", 1);
  await redisMock.rpush("list", 2);
  await redisMock.rpush("list", 3);

  const pop = await redis.rpoplpush("list", "list");
  const popMock = await redisMock.rpoplpush("list", "list");

  const list = await redis.lrange("list", 0, -1);
  const listMock = await redisMock.lrange("list", 0, -1);

  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})`
  );
  assert(
    list === listMock,
    `expected <${listMock.constructor.name}>(${listMock}) to equal <${list.constructor.name}>(${list})`
  );
  return "Success";
};

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

Output:

AssertionError [ERR_ASSERTION]: expected <Array>(3,1,2,3) to equal <Array>(3,1,2)
    at testEquality (/home/matias/dev/workspace/ioredis-mock-example/index.js:31:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}