Registry / testing / mock-redis-client

mock-redis-client

JSON →
library0.91.13jsnpmunverified

A Redis mock for Node.js development, providing in-memory simulation of Redis commands (strings, hashes, lists, pub/sub, transactions, keys, server) without a real Redis server. Current stable version 0.91.13, low release cadence (last update 2016). Designed for unit testing Node.js applications that use the redis npm package. Supports CommonJS require, no TypeScript definitions, no ESM support. Key differentiator: can create a mock redis module that mimics the real redis.createClient API, allowing drop-in replacement. Limited command coverage compared to alternatives like ioredis-mock, and no longer actively maintained.

npm install mock-redis-client
INSTALL
IMPORT
SIG · MOCK-REDIS-CLIENT
M
mock-redis-client
testingjavascriptv0.91.13
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.

MockRedisClient
const MockRedisClient = require('mock-redis-client'); const client = new MockRedisClient();
import MockRedisClient from 'mock-redis-client';
No default export; only CommonJS require works. ESM import will fail.
createMockRedis
const redis = require('mock-redis-client').createMockRedis();
const redis = require('mock-redis-client');
createMockRedis() replaces the redis module for drop-in replacement of real redis client. Must call the function, not just require.
createClient
const client = require('mock-redis-client').createMockRedis().createClient();
const client = require('mock-redis-client').createClient();
createClient is only available on the mock redis object, not the main module directly.

Shows how to use createMockRedis to get a mock client, perform set/get on a string, hset/hgetall on a hash, and cleanup.

const redis = require('mock-redis-client').createMockRedis(); const client = redis.createClient(); client.set('foo', 'bar'); client.get('foo', (err, reply) => { console.log(reply); // 'bar' }); client.hset('hash', 'field1', 'val1', redis.print); client.hgetall('hash', (err, obj) => { console.log(obj); // { field1: 'val1' } }); client.quit();
Debug
Known issues
gotchaNo ESM import support; only CommonJS require works.
fix
Use require('mock-redis-client') instead of import.
affects: >=0.0.0
gotchacreateClient is not exported directly; must use createMockRedis().createClient()
fix
const mockRedis = require('mock-redis-client').createMockRedis(); const client = mockRedis.createClient();
affects: >=0.0.0
deprecatedProject is no longer actively maintained (last release 2016). May have bugs and missing commands.
fix
Consider using ioredis-mock or redis-mock for up-to-date alternatives.
affects: >=0.0.0
gotchadbsize always returns zero, not actual count of keys.
fix
Do not rely on dbsize for testing; use keys or information commands if needed.
affects: >=0.0.0
gotchaNo promise or async/await support; only callbacks.
fix
Wrap with promisify or use a library that supports promises.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: redis.createClient is not a function
Requiring the module directly and calling createClient on it, instead of using createMockRedis().
fix
const redis = require('mock-redis-client').createMockRedis(); const client = redis.createClient();
Error: Cannot find module 'redis'
The package optionally depends on 'redis', which may not be installed.
fix
npm install redis --save-dev or remove the optional dependency (the mock works without redis).
TypeError: client.set(...).then is not a function
Trying to use promises on an object that only supports callbacks.
fix
Use callbacks: client.set('key', 'val', callback) or wrap with util.promisify.
ReferenceError: require is not defined (ESM context)
Using ESM (import/export) which is not supported.
fix
Switch to CommonJS require, or use a dynamic import workaround (not recommended).
Upgrade
Version history
0.91.13latest on npm
Audit
Dependencies
redisoptionalMimics the redis client API for compatibility
Agent activity
2 hits · last 30 days
node
2
Resources
mock-redis-client — npm install mock-redis-client · libregistry