Registry / database / prisma-extension-redis

prisma-extension-redis

JSON →
library2.1.1jsnpmunverified

prisma-extension-redis (v2.1.1) is a Prisma client extension that provides transparent caching and cache invalidation using Redis or Dragonfly databases. It wraps Prisma queries to cache results and automatically invalidate related cache entries on mutations. Key features include configurable cache keys, TTL support, and fine-grained invalidation based on model operations. Released as an npm package, it targets Prisma 4+ and Redis 6+. Unlike manual caching solutions, it integrates seamlessly with Prisma's query lifecycle and works with both Redis and Dragonfly.

npm install prisma-extension-redis
INSTALL
IMPORT
SIG · PRISMA-EXTENSION-R
P
prisma-extension-redis
databasejavascriptv2.1.1
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.

prismaExtensionRedis
import { prismaExtensionRedis } from 'prisma-extension-redis'
const prismaExtensionRedis = require('prisma-extension-redis')
Module is ESM-only; CommonJS require will fail. Use dynamic import if needed.
PrismaRedisCache
import { PrismaRedisCache } from 'prisma-extension-redis'
import PrismaRedisCache from 'prisma-extension-redis'
Named export, not default.
type CacheOptions
import type { CacheOptions } from 'prisma-extension-redis'
import { CacheOptions } from 'prisma-extension-redis'
Type exports are not runtime values; use type import to avoid bundling issues.

Shows how to extend Prisma client with Redis caching, including setup, cached read, and automatic cache invalidation on writes.

import { PrismaClient } from '@prisma/client'; import { createClient } from 'redis'; import { prismaExtensionRedis } from 'prisma-extension-redis'; const redisClient = createClient({ url: process.env.REDIS_URL ?? '' }); await redisClient.connect(); const prisma = new PrismaClient().$extends( prismaExtensionRedis({ models: ['User', 'Post'], cacheOptions: { ttl: 60, invalidation: { onMutation: true } }, storage: { type: 'redis', client: redisClient } }) ); // Cached query const user = await prisma.user.findUnique({ where: { id: 1 } }); // Mutation invalidates cache await prisma.user.update({ where: { id: 1 }, data: { name: 'Alice' } });
Debug
Known issues
gotchaCache invalidation may not propagate across multiple Prisma instances using the same Redis.
fix
Use a shared Redis connection or upgrade to the latest version that supports invalidation events.
affects: <3.0.0
breakingVersion 2.0 changed the extension API: `prismaExtensionRedis` now returns an extension object, not a function. Old code using `new PrismaRedisCache()` will break.
fix
Use `prismaExtensionRedis(options)` instead of `new PrismaRedisCache(options)`.
affects: >=2.0.0
deprecated`prismaExtensionRedis` with `models` as array of strings is deprecated; use `models` as object with per-model configuration.
fix
Migrate to object format: `models: { User: { ttl: 60 }, Post: { ttl: 120 } }`.
affects: >=2.1.0
gotchaUsing `createClient` from `redis` requires calling `connect()` before passing to the extension.
fix
Ensure `await redisClient.connect()` is called before `prisma.$extends()`.
affects: >=1.0.0
gotchaCache keys include Prisma model and query arguments; changing model names will invalidate all cached keys.
fix
Stick to model names consistent across deployments or implement custom key prefix.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: redisClient.connect is not a function
Using a non-async Redis client or calling connect method before v4 of the redis package.
fix
Use `redis` v4+ and install `@redis/client` or `redis` package. Ensure you call `await redisClient.connect()`.
Error: prismaExtensionRedis is not a function
Importing the module incorrectly or using an older version that exports differently.
fix
Use named import: `import { prismaExtensionRedis } from 'prisma-extension-redis'`. For CommonJS, use dynamic import.
PrismaClientKnownRequestError: Invalid prisma.$extends() input: Invalid extension object
Passing options incorrectly to `prismaExtensionRedis` or using unsupported Prisma version.
fix
Ensure you use Prisma >=4.7.0 and pass an options object with `models` and `storage`.
Upgrade
Version history
2.1.1latest on npm
Audit
Dependencies
redisrequiredRequired for connecting to Redis/Dragonfly server
@prisma/clientrequiredPeer dependency for Prisma client extension compatibility
Agent activity
2 hits · last 30 days
node
2
Resources
prisma-extension-redis — npm install prisma-extension-redis · libregistry