v6.0.0
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', nullIn 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.