Emulates ioredis by performing all operations in-memory.
MIT License
Bot releases are visible (Hide)
Published by stipsan over 2 years ago
new Redis(6379, 'localhost', { keyPrefix: 'shared:' })
new Redis('//localhost:6379', { keyPrefix: 'shared:' })
new Redis('redis://localhost:6379', { keyPrefix: 'private:' })
new Redis(6379, { keyPrefix: 'shared:' })
new Redis(6379)
new Redis('redis://localhost:6379/')
Published by stipsan over 2 years ago
'Background append only file rewriting started'
instead of 'OK'
'Background saving started'
instead of 'OK'
"ERR wrong number of arguments for 'decrby' command"
if the decrement argument is missing'WRONGTYPE Operation against a key holding the wrong kind of value'
if the source argument is invalidPublished by stipsan over 2 years ago
There's a browser build available. You can import it directly (import Redis from 'ioredis-mock/browser.js'
), or use it on unpkg.com:
import Redis from 'https://unpkg.com/ioredis-mock';
const redis = new Redis();
redis.set('foo', 'bar');
console.log(await redis.get('foo'));
ioredis-mock/jest.js
is deprecatedioredis-mock
is no longer doing a import { Command } from 'ioredis'
internally, it's now doing a direct import import Command from 'ioredis/built/command'
and thus the jest.js
workaround is no longer needed:
-jest.mock('ioredis', () => require('ioredis-mock/jest'))
+jest.mock('ioredis', () => require('ioredis-mock'))
Published by stipsan over 2 years ago
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 deprecatedReplace it with .duplicate()
or use another new Redis
instance.
Published by stipsan almost 3 years ago