Registry / testing / mock-redis

mock-redis

JSON →
library0.0.3jsnpmunverified

An in-memory mock for basic Redis operations, currently at version 0.0.3. This package implements a subset of Redis functions purely in memory, intended for testing or development scenarios where a real Redis server is unavailable. It is an early-stage project with limited functionality, not suitable for production use. Alternatives like ioredis-mock or redis-mock provide more mature and feature-complete solutions. There is no active maintenance or release cadence.

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

default (MockRedisClient constructor)
import MockRedis from 'mock-redis'; const client = new MockRedis();
const MockRedis = require('mock-redis'); const client = new MockRedis();
CommonJS require works, but ESM import is preferred if your project uses ES modules. The package does not export named exports.
createClient
import { createClient } from 'mock-redis'; const client = createClient();
import createClient from 'mock-redis';
createClient is a named export, not default. This is different from some real Redis clients like redis where createClient is a default export.
MockRedis (class)
import { MockRedis } from 'mock-redis'; const client = new MockRedis();
import MockRedis from 'mock-redis';
MockRedis is a named export. The package does not export a default class.

Basic usage of mock-redis: create a client, set and get a key. Demonstrates both constructor and createClient methods, including callback and Promise patterns.

import { MockRedis, createClient } from 'mock-redis'; // Using the MockRedis class const client1 = new MockRedis(); client1.set('key', 'value', (err, reply) => { if (err) throw err; console.log('SET reply:', reply); // => 'OK' client1.get('key', (err, value) => { console.log('GET value:', value); // => 'value' }); }); // Using createClient function const client2 = createClient(); client2.set('foo', 'bar'); client2.get('foo').then(console.log); // => 'bar'
Debug
Known issues
gotchaPackage is extremely limited: only basic string operations (SET, GET, DEL) are implemented. Commands like HSET, EXPIRE, PUBLISH are not supported.
fix
Use a more complete mock library like ioredis-mock for full Redis command coverage.
affects: all
breakingThe API may not fully mimic the official redis or ioredis clients. Callback signatures and return values might differ.
fix
Check the source code or tests to ensure compatibility with your expected Redis client behavior. Consider using an alternative that matches your real client.
affects: all
deprecatedNo longer maintained: last release was years ago. There are known issues with memory leaks and lack of async/await support in older versions.
fix
Switch to actively maintained alternatives such as ioredis-mock or redis-mock.
affects: all
gotchaDoes not support Redis streams or any persistence features; all data is lost on process exit.
fix
Use only for lightweight development or unit tests; never in production. For persistence, use real Redis or a mock with optional persistence.
affects: all
Errors
Common errors & fixes
Error: Client is not ready
Calling methods before the client is ready (no connect event or callback).
fix
Ensure you wait for the 'ready' event or use the callback in createClient. Example: const client = createClient(() => { /* ready */ });
TypeError: client.set is not a function
Using a client that was not initialized correctly or using a wrong import method (e.g., default import vs named).
fix
Use import { MockRedis } from 'mock-redis' and instantiate with new MockRedis(). Or use createClient().
ReferenceError: MockRedis is not defined
Forgetting to import/require the package or using wrong import statement (CommonJS in ESM context).
fix
Use proper import: import { MockRedis } from 'mock-redis' in ESM, or const { MockRedis } = require('mock-redis') in CommonJS.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

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