DJS Commandsv2 docs
API ReferenceAdapters

adapter-redis

Redis-backed CacheAdapter for distributed cooldowns.

bun add @djs-commands/core @djs-commands/adapter-redis ioredis

The Redis adapter is not a Storage — it's a CacheAdapter for cooldowns. Use it alongside one of the storage adapters.

For setup walk-through see Adapter Cookbook → Redis.

redisCacheAdapter(redis, options?)

function redisCacheAdapter(
	redis: Redis,
	options?: RedisCacheAdapterOptions,
): CacheAdapter;

Returns a CacheAdapter backed by an ioredis client. Pass to createCommandHandler as cacheAdapter.

import { redisCacheAdapter } from "@djs-commands/adapter-redis";
import Redis from "ioredis";

const redis = new Redis(process.env.REDIS_URL!);

createCommandHandler({
	client,
	commands: [...],
	cacheAdapter: redisCacheAdapter(redis),
});

The adapter writes with SET key value PX <ttl> so Redis handles expiry server-side and you never accumulate dead keys.

RedisCacheAdapterOptions

interface RedisCacheAdapterOptions {
	keyPrefix?: string;  // default: "djs-commands:"
}
FieldNotes
keyPrefixPrepended to every key the adapter reads or writes. Use to isolate multiple bots sharing one Redis. Default "djs-commands:".
redisCacheAdapter(redis, { keyPrefix: "moderation-bot:" });

Redis commands used

CacheAdapter methodRedis command
setSET <prefix><key> <expiresAt> PX <ttlMs>
getGET <prefix><key> then parse to number
deleteDEL <prefix><key>

get returns null for missing keys, non-numeric values, or timestamps in the past — defensive against clock skew.

Last updated on

On this page