Registry / testing / node-redis-mock

node-redis-mock

JSON →
library0.2.16jsnpmunverified

Node-redis-mock is a minimal mock implementation of the popular node_redis client for unit testing code that depends on Redis operations. Version 0.2.16 is the latest stable release, with last publish in 2015. It simulates Redis commands in-memory without requiring a running Redis instance. Key differentiators include support for a subset of Redis commands covering strings, hashes, lists, keys, pub/sub, transactions, and server commands. However, it lacks many modern ioredis features and is unmaintained, making it suitable only for legacy projects using node_redis. Release cadence is irregular; no updates in years.

npm install node-redis-mock
INSTALL
IMPORT
SIG · NODE-REDIS-MOCK
N
node-redis-mock
testingjavascriptv0.2.16
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

redis
var redis = require('node-redis-mock');
import redis from 'node-redis-mock';
This package uses CommonJS; ESM import may fail. No TypeScript types.
createClient
var client = redis.createClient();
var client = new redis.createClient();
createClient is a factory function, not a constructor.
redis (with destructuring)
var { createClient } = require('node-redis-mock');
var { createClient } = require('redis-mock');
Common package name confusion with 'redis-mock'.

Shows basic set/get operations using callback style with node-redis-mock.

var redis = require('node-redis-mock'); var client = redis.createClient(); client.set('foo', 'bar', function(err, reply) { if (err) throw err; console.log(reply); // OK client.get('foo', function(err, value) { console.log(value); // bar client.quit(); }); });
Debug
Known issues
deprecatedPackage is unmaintained since 2015 and may not work with newer Node versions (>=12).
fix
Migrate to a maintained mock like redis-mock (newer fork) or ioredis-mock.
affects: >=0.2.16
gotchaMany Redis commands are not implemented: e.g., SORT, SCAN, GEO, etc. Tests may pass unexpectedly.
fix
Check the implemented commands list and add mocks for missing ones, or switch to a more complete mock.
affects: >=0.2.0
breakingdbsize() always returns 0, not the actual key count.
fix
Do not rely on dbsize for accurate key counts in tests.
affects: >=0.2.0
gotchaThe package name is similar to 'redis-mock' and 'ioredis-mock', causing confusion. Installed package may be wrong.
fix
Ensure npm install node-redis-mock yields the correct package.
affects: >=0.2.0
Errors
Common errors & fixes
Error: Cannot find module 'node-redis-mock'
Package not installed or name mistyped.
fix
Run 'npm install node-redis-mock' and verify package.json.
TypeError: redis.createClient is not a function
Default import used with ESM or incorrect require statement.
fix
Use CommonJS require: var redis = require('node-redis-mock');
Redis command 'SET' not implemented
Command not supported by this mock.
fix
Add a manual stub or switch to a mock with broader command support.
Timeout: client did not emit 'ready' within 5000ms
Mock client might not emit 'ready' in all usage patterns.
fix
Call client.emit('ready') manually or ensure client.connect() is called if mock supports it.
Upgrade
Version history
0.2.16latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
node-redis-mock — npm install node-redis-mock · libregistry