Registry / testing / async-redis-mock

async-redis-mock

JSON →
library2.0.1jsnpmunverified

Async Redis client mock object for unit testing that replaces async-redis in test environments. Current stable version is 2.0.1. It is actively maintained and offers in-memory Redis command simulation so that no actual Redis server is needed. Key differentiators: it provides a drop-in replacement for async-redis with a comprehensive set of mocked commands, allowing tests to run quickly and isolated. It supports common Redis commands like SET, GET, DEL, EXPIRE, and more, and integrates easily with testing frameworks like Jest and Mocha.

npm install async-redis-mock
INSTALL
IMPORT
SIG · ASYNC-REDIS-MOCK
A
async-redis-mock
testingjavascriptv2.0.1
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 (mock client)
import asyncRedisMock from 'async-redis-mock';
const asyncRedisMock = require('async-redis-mock');
The package exports a default mock client. CommonJS require also works but ESM is preferred for modern projects.
createClient
import asyncRedisMock from 'async-redis-mock'; const client = asyncRedisMock.createClient();
import { createClient } from 'async-redis-mock';
createClient is a method on the default export, not a named export.
TypeScript types
import asyncRedisMock from 'async-redis-mock'; const client: ReturnType<typeof asyncRedisMock.createClient> = asyncRedisMock.createClient();
import { AsyncRedisMockClient } from 'async-redis-mock';
Types are not exported directly; infer using ReturnType or use async-redis types.

Create a mock Redis client, set and get a key, then quit. Demonstrates in-memory operation.

import asyncRedisMock from 'async-redis-mock'; async function testRedis() { const client = asyncRedisMock.createClient(); await client.set('key', 'value'); const result = await client.get('key'); console.log('Got:', result); // Output: Got: value await client.quit(); } testRedis().catch(console.error);
Debug
Known issues
gotchaNot all Redis commands are implemented; unsupported commands may throw errors or return undefined.
fix
Check the list of implemented commands in the documentation or consider using a different mock if you need full coverage.
affects: <3.0.0
deprecatedThe package is designed for async-redis (v1.x). For newer ioredis or node-redis, use alternative mocks.
fix
If you are using ioredis, consider using 'ioredis-mock' instead.
affects: >=2.0.0
gotchaClean state between tests: mock does not auto-reset; you must manually flush or recreate client.
fix
Call 'client.flushall()' before each test or create a new client in beforeEach.
affects: >=1.0.0
breakingVersion 2.0.0 changed default export from function to object; old 'const mock = require('async-redis-mock')()' breaks.
fix
Use 'import mock from 'async-redis-mock'; const client = mock.createClient();' or 'const mock = require('async-redis-mock').default;' in CJS.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: asyncRedisMock is not a function
Incorrect import after upgrading to v2 where default export changed.
fix
Change to 'import asyncRedisMock from 'async-redis-mock';' or use 'const asyncRedisMock = require('async-redis-mock').default;'
Error: Command 'XADD' is not implemented
Mock does not support the Redis Streams 'XADD' command.
fix
Use only implemented commands (SET, GET, DEL, etc.) or extend the mock manually.
Cannot read property 'createClient' of undefined
Using named import '{ createClient }' instead of default import.
fix
Use 'import asyncRedisMock from 'async-redis-mock';' then 'asyncRedisMock.createClient()'.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
async-redisrequiredProvides the API surface that this mock replicates; used for type definitions and compatibility.
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
async-redis-mock — npm install async-redis-mock · libregistry