Skip to content

Redis Adapter

The Redis adapter is the recommended choice for production environments. It allows multiple server instances to share the same cache and persist data across restarts.

Installation

bash
npm install @express-route-cache/redis ioredis

Setup

ts
import { createCache } from "@express-route-cache/core";
import { createRedisAdapter } from "@express-route-cache/redis";

// Option 1: Connect via URL
const adapter = createRedisAdapter({ url: "redis://localhost:6379" });

// Option 2: Use an existing ioredis client
const adapter = createRedisAdapter({ client: myExistingClient });

const cache = createCache({ adapter });

Options

The createRedisAdapter function accepts either a url string or an options object:

OptionTypeDescription
urlstringRedis connection URL.
clientRedisAn existing ioredis instance.
keyPrefixstringPrefix for all cache keys (default: erc:).

Performance

This adapter uses Redis MGET and INCR for O(1) performance. It is highly optimized for high-throughput Express applications.

Released under the MIT License.