npm ioredis-mock 6.0.0
v6.0.0

latest releases: 8.9.0, 7.5.1, 8.8.3...
2 years ago

6.0.0 (2022-01-25)

BREAKING CHANGE

Before v6, each instance of ioredis-mock lived in isolation:

const Redis = require('ioredis-mock');
const redis1 = new Redis();
const redis2 = new Redis();
await redis1.set('foo', 'bar');
console.log(await redis1.get('foo'), await redis2.get('foo')); // 'bar', null

In v6 the internals were rewritten to behave more like real life redis, if the host and port is the same, the context is now shared:

const Redis = require('ioredis-mock');
const redis1 = new Redis();
const redis2 = new Redis();
const redis3 = new Redis({ port: 6380 }); // 6379 is the default port
await redis1.set('foo', 'bar');
console.log(
  await redis1.get('foo'), // 'bar'
  await redis2.get('foo'), // 'bar'
  await redis3.get('foo') // null
);

And since ioredis-mock now persist data between instances, you'll likely need to run flushall between testing suites:

const Redis = require('ioredis-mock');
afterEach((done) => {
  new Redis().flushall().then(() => done());
});

createConnectedClient is deprecated

Replace it with .duplicate() or use another new Redis instance.

Don't miss a new ioredis-mock release

NewReleases is sending notifications on new releases.