Registry / database / payloadcms-redis-cache

payloadcms-redis-cache

JSON →
library1.0.3jsnpmunverified

A lightweight Redis caching utility for Payload CMS v3 and Next.js 14+ App Router applications, currently at version 1.0.3. It provides a simple Redis client wrapper, server-only safe, with TypeScript and ESM support. Key differentiators: designed specifically for Payload CMS v3, supports collection caching and cache invalidation hooks, and includes examples for API routes and Next.js client components. The package is actively maintained by a single author and has an MIT license.

npm install payloadcms-redis-cache
INSTALL
IMPORT
SIG · PAYLOADCMS-REDIS-C
P
payloadcms-redis-cache
databasejavascriptv1.0.3
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.

redis
import { redis } from 'payloadcms-redis-cache'
import redis from 'payloadcms-redis-cache'
Named export, not default. In ESM, use named import.
PayloadCache
import { PayloadCache } from 'payloadcms-redis-cache'
const PayloadCache = require('payloadcms-redis-cache').PayloadCache
This symbol is not documented yet but may be added in future. For v1.0.3, only redis is exported.
redisClient
import { redis } from 'payloadcms-redis-cache'
import { redisClient } from 'payloadcms-redis-cache'
The exported object is named 'redis'. There is no 'redisClient'. Use the correct name.

Demonstrates basic Redis set and get operations using the exported redis client. Shows TTL option.

import { redis } from 'payloadcms-redis-cache' async function example() { await redis.set('hello', 'world', { EX: 60 }) const value = await redis.get('hello') console.log(value) // 'world' }
Debug
Known issues
gotchaThe redis instance is a thin wrapper around ioredis. Ensure ioredis is installed as a peer dependency or included automatically.
fix
Run 'npm install ioredis' if missing.
affects: >=1.0.0
gotchaDo not import or use redis inside Next.js client components or browser code. It will throw errors at runtime because ioredis uses Node.js APIs.
fix
Only use in server components, API routes, or server actions.
affects: >=1.0.0
deprecatedThe package is in early development (v1.0.3); API may change. No deprecations yet.
fix
Pin version to avoid breaking changes: 'payloadcms-redis-cache': '1.0.3'
affects: 1.0.3
gotchaEnsure REDIS_HOST, REDIS_PORT, and REDIS_PASSWORD environment variables are set. Missing variables cause silent connection failures.
fix
Set .env or process.env values before calling redis methods.
affects: >=1.0.0
Errors
Common errors & fixes
Redis connection error: connect ECONNREFUSED 127.0.0.1:6379
Redis server not running or environment variables misconfigured.
fix
Start Redis server (e.g., 'brew services start redis' on Mac). Verify REDIS_HOST and REDIS_PORT.
UnhandledPromiseRejectionWarning: TypeError: redis.set is not a function
Importing incorrectly (default import instead of named).
fix
Use 'import { redis } from 'payloadcms-redis-cache' instead of 'import redis from ...'
ReferenceError: window is not defined
Using ioredis (Node.js) in browser environment.
fix
Move redis usage to server-only code: API routes, server components, or server actions.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
ioredisrequiredRedis client used internally
Agent activity
4 hits · last 30 days
node
4
Resources
payloadcms-redis-cache — npm install payloadcms-redis-cache · libregistry