harsh2august

payloadcms redis cache

by harsh2august
Databases & data
v?

Overview

Summary generated from the README

Exposes a ready-to-use Redis client for Payload CMS v3 and Next.js App Router projects. You import it in API routes, hooks, server components or server actions to cache query results and delete keys from Payload afterChange and afterDelete hooks. It reads connection settings from environment variables and requires a Redis server, Node.js 18+ and Next.js 14+.

Features

  • Redis client configured through host, port and password environment variables
  • Cache Payload find results with a time-to-live in API routes
  • Invalidate cached keys from collection afterChange and afterDelete hooks
  • TypeScript and ESM support
  • Server-only usage for API routes, hooks, server components and actions

Use cases

  • Cache frequently requested collection data such as hero sliders to reduce database queries
  • Clear cached responses automatically when editors change or delete documents
  • Add a Redis cache layer to a self-hosted Payload and Next.js deployment on a VPS

From the author

Payload CMS Redis Cache Plugin

Installation

npm i payloadcms-redis-cache

2

Stars

0

Forks

0

Open Issues

6 months ago

Last Updated

16

Weekly Downloads

v1.0.3

npm Version

205.1 KB

Unpacked Size

2

Dependencies

GitHub stars

20 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 20262
Dec 4, 20262
Dec 3, 20262
Dec 2, 20262
Dec 1, 20262
Nov 30, 20262
Nov 29, 20262
Nov 28, 20262
Nov 27, 20262
Nov 26, 20262
Nov 25, 20262
Nov 24, 20262
Nov 23, 20262
Nov 22, 20262
Nov 21, 20262
Nov 20, 20262
Nov 19, 20262
Nov 18, 20262
Nov 17, 20262
Nov 16, 20262
Nov 15, 20262
Nov 14, 20262
Nov 13, 20262
Nov 12, 20262
Nov 11, 20262
Nov 10, 20262
Nov 9, 20262
Nov 8, 20262
Nov 7, 20262
Nov 6, 20262
Nov 5, 20262
Nov 4, 20262
Nov 3, 20262
Nov 2, 20262
Nov 1, 20262
Oct 31, 20262
Oct 30, 20262
Oct 29, 20262
Oct 28, 20262
Oct 27, 20262
Oct 26, 20262
Oct 25, 20262
Oct 24, 20262
Oct 23, 20262
Oct 22, 20262
Oct 21, 20262
Oct 20, 20262
Oct 19, 20262
Oct 18, 20262
Oct 17, 20262
Oct 16, 20262
Oct 15, 20262
Oct 14, 20262
Oct 13, 20262
Oct 12, 20262
Oct 11, 20262
Oct 10, 20262
Oct 9, 20262
Oct 8, 20262
Oct 7, 20262
Oct 6, 20262
Oct 5, 20262
Oct 4, 20262
Oct 3, 20262
Oct 2, 20262
Oct 1, 20262
Sep 30, 20262
Sep 29, 20262
Sep 28, 20262
Sep 27, 20262
Sep 26, 20262
Sep 25, 20262
Sep 24, 20262
Sep 23, 20262
Sep 22, 20262
Sep 21, 20262
Sep 20, 20262
Sep 19, 20262
Sep 18, 20262
Sep 17, 20262
Sep 16, 20262
Sep 15, 20262
Sep 14, 20262
Sep 13, 20262
Sep 12, 20262
Sep 11, 20262
Sep 10, 20262
Sep 9, 20262
Sep 8, 20262
Sep 7, 20262
Sep 6, 20262
npm weekly downloads

5−9 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 20265
Dec 4, 20265
Dec 3, 20266
Dec 2, 20265
Dec 1, 202611
Nov 30, 202612
Nov 29, 20269
Nov 28, 20269
Nov 27, 20269
Nov 26, 20268
Nov 25, 20268
Nov 24, 20262
Nov 23, 20261
Nov 22, 20263
Nov 21, 20263
Nov 20, 20266
Nov 19, 20267
Nov 18, 20268
Nov 17, 20268
Nov 16, 20269
Nov 15, 202610
Nov 14, 202610
Nov 13, 20268
Nov 12, 202612
Nov 11, 202612
Nov 10, 202613
Nov 9, 202612
Nov 8, 202610
Nov 7, 202615
Nov 6, 202613
Nov 5, 20268
Nov 4, 20267
Nov 3, 20266
Nov 2, 20268
Nov 1, 20268
Oct 31, 20263
Oct 30, 20263
Oct 29, 20263
Oct 28, 20263
Oct 27, 20264
Oct 26, 20263
Oct 25, 20262
Oct 24, 20263
Oct 23, 20263
Oct 22, 20265
Oct 21, 20265
Oct 20, 20264
Oct 19, 20263
Oct 18, 20263
Oct 17, 20263
Oct 16, 20263
Oct 15, 20262
Oct 14, 20262
Oct 13, 20262
Oct 12, 20262
Oct 11, 20263
Oct 10, 20262
Oct 9, 20262
Oct 8, 20261
Oct 7, 20261
Oct 6, 20261
Oct 5, 20261
Oct 4, 20263
Oct 3, 20263
Oct 2, 20265
Oct 1, 20265
Sep 30, 20265
Sep 29, 20265
Sep 28, 20265
Sep 27, 20262
Sep 26, 20265
Sep 25, 20263
Sep 24, 20263
Sep 23, 20263
Sep 22, 20267
Sep 21, 202622
Sep 20, 202623
Sep 19, 202624
Sep 18, 202624
Sep 17, 202625
Sep 16, 202627
Sep 15, 202623
Sep 14, 202610
Sep 13, 20269
Sep 12, 20268
Sep 11, 202612
Sep 10, 202611
Sep 9, 202614
Sep 8, 202614
Sep 7, 202614
Sep 6, 202614

Each point is npm's rolling 7-day download count.

Health Score

38/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1252295341-root.svg)](https://payloaddirectory.dev/plugins/1252295341-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1252295341-root"><img src="https://payloaddirectory.dev/badge/1252295341-root.svg" alt="Payload Directory"></a>
Updated May 28, 2026Created May 28, 2026Published May 28, 2026

README

payloadcms-redis-cache

Redis cache utilities for Payload CMS and Next.js applications.

A lightweight Redis helper package built for modern Payload CMS v3 + Next.js App Router projects.


Features

  • ✅ Redis client for Payload CMS
  • ✅ Next.js App Router support
  • ✅ Payload collection caching
  • ✅ Cache invalidation helpers
  • ✅ TypeScript support
  • ✅ ESM support
  • ✅ Server-only safe
  • ✅ Works with local Redis and VPS Redis
  • ✅ Payload CMS v3 compatible

Installation

npm install payloadcms-redis-cache

Requirements

  • Node.js 18+
  • Redis Server
  • Payload CMS v3+
  • Next.js 14+

Environment Variables

Create a .env file:

REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=

Production Example:

REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=yourpassword

Basic Usage

Redis Client

import { redis } from 'payloadcms-redis-cache'

await redis.set('hello', 'world')

const value = await redis.get('hello')

console.log(value)

Payload CMS Collection Caching

Example API Route

import { getPayload } from 'payload'
import payloadConfig from '@/payload.config'
import { redis } from 'payloadcms-redis-cache'

export async function GET() {
  const cached = await redis.get('hero-slider')

  if (cached) {
    return Response.json({
      docs: JSON.parse(cached),
    })
  }

  const payload = await getPayload({
    config: payloadConfig,
  })

  const data = await payload.find({
    collection: 'heroslider',
  })

  await redis.set(
    'hero-slider',
    JSON.stringify(data.docs),
    {
      EX: 3600,
    }
  )

  return Response.json(data)
}

Cache Invalidation

Payload Collection Hook

hooks: {
  afterChange: [
    async () => {
      await redis.del('hero-slider')
    },
  ],

  afterDelete: [
    async () => {
      await redis.del('hero-slider')
    },
  ],
}

Next.js Client Component

'use client'

import { useEffect, useState } from 'react'

export default function HeroSlider() {
  const [slides, setSlides] = useState([])

  useEffect(() => {
    const fetchSlides = async () => {
      const res = await fetch('/api/heroslider-api')

      const data = await res.json()

      setSlides(data.docs || [])
    }

    fetchSlides()
  }, [])

  return <div>{slides.length}</div>
}

Important

Redis should only be used on the server.

Do NOT import Redis inside:

  • Client Components
  • Browser code
  • useEffect Redis logic

Correct usage locations:

  • API routes
  • Payload hooks
  • Server components
  • Server actions

Local Redis Setup (Mac)

Install Redis:

brew install redis

Start Redis:

brew services start redis

Verify:

redis-cli ping

Expected:

PONG

VPS Redis Setup

Recommended production settings:

bind 127.0.0.1 ::1
protected-mode yes

Do not expose Redis publicly.


Tech Stack

  • Payload CMS
  • Next.js
  • Redis
  • TypeScript
  • tsup

Roadmap

  • cacheCollection helper
  • invalidateCache helper
  • cacheGlobal helper
  • automatic Payload hooks
  • tag-based invalidation
  • Redis Insight integration examples
  • BullMQ support

License

MIT


Author

Harsh Kumar


Contributing

Pull requests and issues are welcome.


Similar plugins