Configuration
There are two ways to run your plugins against the in-memory driver.
Option 1 — RedisTestingModule (recommended)
The wrapper forces the in-memory driver and fills in the (ignored) connection config for you. Register the same plugins you use in production:
import { Module } from '@nestjs/common';
import { CachePlugin } from '@nestjs-redisx/cache';
import { RateLimitPlugin } from '@nestjs-redisx/rate-limit';
import { RedisTestingModule } from '@nestjs-redisx/testing';
/**
* `RedisTestingModule` is an ergonomic wrapper around `RedisModule` that forces
* the in-memory driver for you — no `global.driver` or `clients` boilerplate.
* Register the same plugins you use in production to test their real behavior.
*/
@Module({
imports: [
RedisTestingModule.forRoot({
plugins: [new CachePlugin(), new RateLimitPlugin({ defaultAlgorithm: 'token-bucket', defaultPoints: 5, defaultDuration: 60 })],
}),
],
})
export class TestAppModule {}RedisTestingModule.forRootAsync(...) is also available and mirrors RedisModule.forRootAsync — its useFactory may omit clients.
Option 2 — global.driver on RedisModule
If you prefer to configure RedisModule directly, import the package once (to register the driver) and set global.driver:
import { Module } from '@nestjs/common';
import { RedisModule } from '@nestjs-redisx/core';
import { CachePlugin } from '@nestjs-redisx/cache';
import { LocksPlugin } from '@nestjs-redisx/locks';
// Importing the package registers the 'memory' driver with the core registry.
import '@nestjs-redisx/testing';
/**
* A test module that runs the real plugins against the in-memory driver.
* Setting `global.driver = 'memory'` swaps the transport — no Redis required.
* The `clients` block is still required but its host/port are ignored.
*/
@Module({
imports: [
RedisModule.forRoot({
clients: { type: 'single', host: 'localhost', port: 6379 },
global: { driver: 'memory' },
plugins: [new CachePlugin(), new LocksPlugin()],
}),
],
})
export class TestAppModule {}TIP
Importing @nestjs-redisx/testing anywhere registers the 'memory' driver as a side effect. The clients block is still required by RedisModule, but its host/port are never used — the in-memory driver does not connect.
Manual registration
The driver is registered automatically on import, but you can call the function explicitly (it is idempotent):
import { registerMemoryDriver } from '@nestjs-redisx/testing';
registerMemoryDriver();This plugs into the core driver registry, so any RedisModule.forRoot({ global: { driver: 'memory' } }) — across the whole app — can construct it.
Driver options
IMemoryDriverOptions are passed through the standard driver factory options.
| Option | Type | Default | Description |
|---|---|---|---|
enableLogging | boolean | false | Inherited driver operation logging. |
seed | Record<string, string> | — | Reserved for seeding string keys (see Testing Plugins for the getStore() approach available today). |
Isolation between tests
Each MemoryRedisAdapter instance owns a private keyspace. A fresh Nest context (per test or per suite) starts empty. To reset state within a single context, use the store directly — see Testing Plugins → Seeding and inspecting state.