Registry / testing / fastify-redis-mock

fastify-redis-mock

JSON →
library1.1.0jsnpmunverified

A Fastify plugin that provides a shared in-memory Redis mock client for unit testing, built on top of ioredis-mock. Version 1.1.0 is the latest stable release. It mirrors the fastify-redis API, allowing seamless switching between real and mock Redis clients for testing without a live Redis server. Maintained with low release cadence.

npm install fastify-redis-mock
INSTALL
IMPORT
SIG · FASTIFY-REDIS-MOCK
F
fastify-redis-mock
testingjavascriptv1.1.0
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 export
import redisMock from 'fastify-redis-mock'
const redisMock = require('fastify-redis')
This is a Fastify plugin, typically passed to fastify.register(). The package exports a single plugin function.
CommonJS require
const redisMock = require('fastify-redis-mock')
const { default } = require('fastify-redis-mock')
CJS default export is directly the module.exports, no destructuring needed.
TypeScript usage (no types shipped)
// @ts-ignore import redisMock from 'fastify-redis-mock'
import { RedisMock } from 'fastify-redis-mock'
Package does not include TypeScript declarations. Use ioredis-mock types or declare module.
register with options
fastify.register(redisMock, { /* options */ })
fastify.register(redisMock, /* options */)
Second argument must be an object (options), not a primitive. Accepts same options as ioredis-mock.

Registers the fastify-redis-mock plugin and uses the mock client to get a key.

import Fastify from 'fastify'; import redisMock from 'fastify-redis-mock'; const app = Fastify({ logger: true }); await app.register(redisMock, { /* ioredis-mock options */ }); app.get('/key/:key', async (req, reply) => { const value = await app.redis.get(req.params.key); return { key: req.params.key, value }; }); await app.listen({ port: 3000 });
Debug
Known issues
gotchaThe mock client does not persist data across fastify instances. Each instance gets its own mock database.
fix
Use a single fastify instance if shared state is needed, or use a global mock store.
affects: >=1.0.0
gotchaSome Redis commands (e.g., PUB/SUB, CLUSTER) are not supported by ioredis-mock. These will throw or return errors.
fix
Check ioredis-mock documentation for supported commands. Mock only commands your code actually uses.
affects: >=1.0.0
gotchaWhen switching between real Redis and mock, ensure the same options object shape is used. fastify-redis expects different options than ioredis-mock.
fix
Use a wrapper function to normalize options depending on environment.
affects: >=1.0.0
breakingThe plugin does not support Fastify v4's plugin encapsulation model for async hooks. If you use onReady or preHandler, the mock client might not be available.
fix
Guarantee registration in the root scope, or use fastify.after() to access redis.
affects: >=1.0.0
deprecatedThis package is not actively maintained. Use at your own risk for production testing.
fix
Consider using fastify-redis with a local Redis instance or a dedicated test container.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'fastify-redis-mock'
Package not installed or typo in require/import
fix
Run `npm install fastify-redis-mock --save-dev` and check spelling.
TypeError: redis.get is not a function
The plugin was not registered before accessing fastify.redis
fix
Make sure to call `await fastify.register(redisMock)` before any route handlers or hooks that use redis.
FST_ERR_PLUGIN_VERSION_MISMATCH: fastify-redis-mock expects fastify version >=x.x.x
Incompatible Fastify version (e.g., using Fastify v4 when the plugin requires v3)
fix
Check the plugin's peerDependencies and install a compatible Fastify version.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
fastifyrequiredPeer dependency – plugin requires Fastify to register
ioredis-mockrequiredUnderlying mock Redis implementation
Agent activity
2 hits · last 30 days
node
2
Resources
fastify-redis-mock — npm install fastify-redis-mock · libregistry