Gathering detailed insights and metrics for ioredis-mock
Gathering detailed insights and metrics for ioredis-mock
Gathering detailed insights and metrics for ioredis-mock
Gathering detailed insights and metrics for ioredis-mock
@types/ioredis-mock
TypeScript definitions for ioredis-mock
rcc-ioredis-mock-adapter
Wraps and adapts the 'ioredis-mock' module & its Redis client instances to be used with the 'redis-client-cache' module
@quirrel/ioredis-mock
This library emulates ioredis by performing all operations in-memory.
@kess-flow/ioredis-mock
This library emulates ioredis by performing all operations in-memory.
npm install ioredis-mock
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
360 Stars
1,286 Commits
131 Forks
4 Watchers
12 Branches
90 Contributors
Updated on Jun 28, 2025
Latest Version
8.9.0
Package Id
ioredis-mock@8.9.0
Unpacked Size
6.65 MB
Size
1.46 MB
File Count
13
NPM Version
9.6.7
Node Version
18.18.0
Published on
Sep 29, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
38
This library emulates ioredis by performing all operations in-memory. The best way to do integration testing against redis and ioredis is on a real redis-server instance. However, there are cases where mocking the redis-server is a better option.
Cases like:
Check the compatibility table for supported redis commands.
1const Redis = require('ioredis-mock')
2const redis = new Redis({
3 // `options.data` does not exist in `ioredis`, only `ioredis-mock`
4 data: {
5 user_next: '3',
6 emails: {
7 'clark@daily.planet': '1',
8 'bruce@wayne.enterprises': '2',
9 },
10 'user:1': { id: '1', username: 'superman', email: 'clark@daily.planet' },
11 'user:2': { id: '2', username: 'batman', email: 'bruce@wayne.enterprises' },
12 },
13})
14// Basically use it just like ioredis
There's a browser build available. You can import it directly (import Redis from 'ioredis-mock/browser.js'
), or use it on unpkg.com:
1import Redis from 'https://unpkg.com/ioredis-mock' 2 3const redis = new Redis() 4redis.set('foo', 'bar') 5console.log(await redis.get('foo'))
ioredis@v4
support droppedioredis@v5
is the new baseline. Stay on ioredis-mock@v7
until you're ready to upgrade to ioredis@v5
.
PromiseContainer
has been removed.Support for third-party Promise libraries is dropped. The native Promise library will always be used.
createConnectedClient
is removedReplace it with .duplicate()
or use another new Redis
instance.
It's been EOL since Apr, 2021 and it's recommended to upgrade to v14.x LTS.
ioredis-mock/jest.js
is removedioredis-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:
1-jest.mock('ioredis', () => require('ioredis-mock/jest')) 2+jest.mock('ioredis', () => require('ioredis-mock'))
Before v6, each instance of ioredis-mock
lived in isolation:
1const Redis = require('ioredis-mock') 2const redis1 = new Redis() 3const redis2 = new Redis() 4 5await redis1.set('foo', 'bar') 6console.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:
1const Redis = require('ioredis-mock') 2const redis1 = new Redis() 3const redis2 = new Redis() 4const redis3 = new Redis(6380) // 6379 is the default port 5 6await redis1.set('foo', 'bar') 7console.log( 8 await redis1.get('foo'), // 'bar' 9 await redis2.get('foo'), // 'bar' 10 await redis3.get('foo') // null 11)
And since ioredis-mock
now persist data between instances, you'll likely need to run flushall
between testing suites:
1const Redis = require('ioredis-mock') 2 3afterEach(done => { 4 new Redis().flushall().then(() => done()) 5})
We also support redis publish/subscribe channels. Like ioredis, you need two clients:
1const Redis = require('ioredis-mock') 2const redisPub = new Redis() 3const redisSub = new Redis() 4 5redisSub.on('message', (channel, message) => { 6 console.log(`Received ${message} from ${channel}`) 7}) 8redisSub.subscribe('emails') 9redisPub.publish('emails', 'clark@daily.planet')
You can use the defineCommand
to define custom commands using lua or eval
to directly execute lua code.
In order to create custom commands, using lua scripting, ioredis exposes the defineCommand method.
You could define a custom command multiply
which accepts one
key and one argument. A redis key, where you can get the multiplicand, and an argument which will be the multiplicator:
1const Redis = require('ioredis-mock') 2const redis = new Redis({ data: { k1: 5 } }) 3const commandDefinition = { 4 numberOfKeys: 1, 5 lua: 'return redis.call("GET", KEYS[1]) * ARGV[1]', 6} 7redis.defineCommand('multiply', commandDefinition) // defineCommand(name, definition) 8// now we can call our brand new multiply command as an ordinary command 9redis.multiply('k1', 10).then(result => { 10 expect(result).toBe(5 * 10) 11})
You can also achieve the same effect by using the eval
command:
1const Redis = require('ioredis-mock') 2const redis = new Redis({ data: { k1: 5 } }) 3const result = redis.eval(`return redis.call("GET", "k1") * 10`) 4expect(result).toBe(5 * 10)
note we are calling the ordinary redis GET
command by using the global redis
object's call
method.
As a difference from ioredis we currently don't support:
multiply
the multiplyBuffer
which returns values using Buffer.from(...)
)evalsha
commandscript
commandWork on Cluster support has started, the current implementation is minimal and PRs welcome #359
1const Redis = require('ioredis-mock') 2 3const cluster = new Redis.Cluster(['redis://localhost:7001']) 4const nodes = cluster.nodes() 5expect(nodes.length).toEqual(1)
You can check the roadmap project page, and the compat table, to see how close we are to feature parity with ioredis
.
Just create an issue and tell us all about it or submit a PR with it! 😄
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
dependency not pinned by hash detected -- score normalized to 6
Details
Reason
Found 6/21 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
security policy file not detected
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
project is not fuzzed
Details
Reason
27 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More