Gathering detailed insights and metrics for @kess-flow/ioredis-mock
Gathering detailed insights and metrics for @kess-flow/ioredis-mock
Gathering detailed insights and metrics for @kess-flow/ioredis-mock
Gathering detailed insights and metrics for @kess-flow/ioredis-mock
Emulates ioredis by performing all operations in-memory.
npm install @kess-flow/ioredis-mock
Typescript
Module System
Min. Node Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
870 Commits
4 Branches
1 Contributors
Updated on Mar 04, 2021
Latest Version
5.2.7
Package Id
@kess-flow/ioredis-mock@5.2.7
Unpacked Size
176.26 kB
Size
36.51 kB
File Count
162
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
9
1
23
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.
1var Redis = require('ioredis-mock');
2var 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
We also support redis publish/subscribe channels (just like ioredis). Like ioredis, you need two clients:
1var Redis = require('ioredis-mock'); 2var redisPubSub = new Redis(); 3// create a second Redis Mock (connected to redisPubSub) 4var redisSync = redisPubSub.createConnectedClient(); 5redisPubSub.on('message', (channel, message) => { 6 expect(channel).toBe('emails'); 7 expect(message).toBe('clark@daily.planet'); 8 done(); 9}); 10redisPubSub.subscribe('emails'); 11redisSync.publish('emails', 'clark@daily.planet');
By default, ioredis-mock uses the native Promise library. If you need (or prefer) bluebird promises, set Redis.Promise
:
1var Promise = require('bluebird'); 2var Redis = require('ioredis-mock'); 3 4Redis.Promise = Promise;
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:
1var Redis = require('ioredis-mock'); 2const redis = new Redis({ data: { 'k1': 5 } }); 3const commandDefinition: { numberOfKeys: 1, lua: 'return KEYS[1] * ARGV[1]' }; 4redis.defineCommand('MULTIPLY', commandDefinition) // defineCommand(name, definition) 5 // now we can call our brand new multiply command as an ordinary command 6 .then(() => redis.multiply('k1', 10)); 7 .then(result => { 8 expect(result).toBe(5 * 10); 9 })
You can also achieve the same effect by using the eval
command:
1var 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
commandThis project started off as just an utility in another project and got open sourced to benefit the rest of the ioredis community. This means there's work to do before it's feature complete:
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
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
no SAST tool detected
Details
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
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