Skip to content

Commit 8f477d1

Browse files
authored
Merge branch 'main' into allow-redis-client-settings
2 parents 9f80dd6 + 01eb844 commit 8f477d1

File tree

5 files changed

+43
-29
lines changed

5 files changed

+43
-29
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [1.5.1](https://github.com/trieb-work/nextjs-turbo-redis-cache/compare/v1.5.0...v1.5.1) (2025-05-23)
2+
3+
4+
### Bug Fixes
5+
6+
* Update package.json ([63e6ffd](https://github.com/trieb-work/nextjs-turbo-redis-cache/commit/63e6ffdc21032cfb1c5ecb507276fd832ee8252a))
7+
18
# [1.5.0](https://github.com/trieb-work/nextjs-turbo-redis-cache/compare/v1.4.0...v1.5.0) (2025-05-16)
29

310

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![npm version](https://img.shields.io/npm/v/@trieb.work/nextjs-turbo-redis-cache.svg)](https://www.npmjs.com/package/@trieb.work/nextjs-turbo-redis-cache)
44
![Turbo redis cache image](https://github.com/user-attachments/assets/98e0dfd9-f38a-42ad-a355-9843740cc2d6)
55

6-
The ultimate Redis caching solution for Next.js. Built for production-ready, large-scale projects, it delivers unparalleled performance and efficiency with features tailored for high-traffic applications. This package has been created after extensibly testing the @neshca package and finding several major issues with it.
6+
The ultimate Redis caching solution for Next.js 15 and the app router. Built for production-ready, large-scale projects, it delivers unparalleled performance and efficiency with features tailored for high-traffic applications. This package has been created after extensibly testing the @neshca package and finding several major issues with it.
77

88
Key Features:
99

@@ -13,6 +13,8 @@ Key Features:
1313
- _Efficient Tag Management_: in-memory tags map for lightning-fast revalidate operations with minimal Redis overhead.
1414
- _Intelligent Key-Space Notifications_: Automatic update of in-memory tags map for expired or evicted keys.
1515

16+
This library offers you an easy and high performant caching solution for docker, Kubernetes or Google Cloud Run deployments of Next.js.
17+
1618
## Compatibility
1719

1820
This package is compatible with Next.js 15.0.3 and above while using App Router. It is not compatible with Next.js 14.x. or 15-canary or if you are using Pages Router.
@@ -46,6 +48,8 @@ REDISHOST and REDISPORT environment variables are required.
4648
VERCEL_URL, VERCEL_ENV are optional. VERCEL_URL is used to create a key prefix for the redis keys. VERCEL_ENV is used to determine the database to use. Only VERCEL_ENV=production will show up in DB 0 (redis default db). All other values of VERCEL_ENV will use DB 1, use `redis-cli -n 1` to connect to different DB 1. This is another protection feature to avoid that different environments (e.g. staging and production) will overwrite each other.
4749
Furthermore there exists the DEBUG_CACHE_HANDLER environment variable to enable debug logging of the caching handler once it is set to true.
4850

51+
There exists also the SKIP_KEYSPACE_CONFIG_CHECK environment variable to skip the check for the keyspace configuration. This is useful if you are using redis in a cloud environment that forbids access to config commands. If you set SKIP_KEYSPACE_CONFIG_CHECK=true the check will be skipped and the keyspace configuration will be assumed to be correct (e.g. notify-keyspace-events Exe).
52+
4953
### Option A: minimum implementation with default options
5054

5155
extend `next.config.js` with:
@@ -117,7 +121,7 @@ A working example of above can be found in the `test/integration/next-app-custom
117121

118122
| Option | Description | Default Value |
119123
| ---------------------- | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
120-
| redis_url | Redis connection url | `process.env.REDIS_URL? process.env.REDIS_URL : process.env.REDISHOST ? redis://${process.env.REDISHOST}:${process.env.REDISPORT} : 'redis://localhost:6379'` |
124+
| redisUrl | Redis connection url | `process.env.REDIS_URL? process.env.REDIS_URL : process.env.REDISHOST ? redis://${process.env.REDISHOST}:${process.env.REDISPORT} : 'redis://localhost:6379'` |
121125
| database | Redis database number to use. Uses DB 0 for production, DB 1 otherwise | `process.env.VERCEL_ENV === 'production' ? 0 : 1` |
122126
| keyPrefix | Prefix added to all Redis keys | `process.env.VERCEL_URL \|\| 'UNDEFINED_URL_'` |
123127
| sharedTagsKey | Key used to store shared tags hash map in Redis | `'__sharedTags__'` |
@@ -197,28 +201,26 @@ By accepting and tolerating this eventual consistency, the performance of the ca
197201

198202
## Testing
199203

200-
Run `pnpm run-dev-server` to start the nextjs integration test project.
201-
202-
To run all tests you can use the following command in a second terminal:
204+
To run all tests you can use the following command:
203205

204206
```bash
205-
pnpm test
207+
pnpm build && pnpm test
206208
```
207209

208210
### Unit tests
209211

210212
To run unit tests you can use the following command:
211213

212214
```bash
213-
pnpm test:unit
215+
pnpm build && pnpm test:unit
214216
```
215217

216218
### Integration tests
217219

218220
To run integration tests you can use the following command:
219221

220222
```bash
221-
pnpm test:integration
223+
pnpm build && pnpm test:integration
222224
```
223225

224226
The integration tests will start a Next.js server and test the caching handler. You can modify testing behavior by setting the following environment variables:

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@trieb.work/nextjs-turbo-redis-cache",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/trieb-work/nextjs-turbo-redis-cache.git"
@@ -51,7 +51,7 @@
5151
],
5252
"author": "Designed for speed, scalability, and optimized performance, nextjs-turbo-redis-cache is your go-to solution for Next.js caching in demanding production environments.",
5353
"license": "ISC",
54-
"description": "",
54+
"description": "Next.js redis cache handler",
5555
"publishConfig": {
5656
"access": "public"
5757
},

src/RedisStringsHandler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ export type CacheEntry = {
1414
};
1515

1616
export type CreateRedisStringsHandlerOptions = {
17-
/** Redis redis_url to use.
17+
/** Redis redisUrl to use.
1818
* @default process.env.REDIS_URL? process.env.REDIS_URL : process.env.REDISHOST
1919
? `redis://${process.env.REDISHOST}:${process.env.REDISPORT}`
2020
: 'redis://localhost:6379'
2121
*/
22-
redis_url?: string;
22+
redisUrl?: string;
2323
/** Redis database number to use. Uses DB 0 for production, DB 1 otherwise
2424
* @default process.env.VERCEL_ENV === 'production' ? 0 : 1
2525
*/
@@ -105,7 +105,7 @@ export default class RedisStringsHandler {
105105
private estimateExpireAge: (staleAge: number) => number;
106106

107107
constructor({
108-
redis_url = process.env.REDIS_URL
108+
redisUrl = process.env.REDIS_URL
109109
? process.env.REDIS_URL
110110
: process.env.REDISHOST
111111
? `redis://${process.env.REDISHOST}:${process.env.REDISPORT}`
@@ -134,8 +134,8 @@ export default class RedisStringsHandler {
134134
try {
135135
// Create Redis client with properly typed configuration
136136
this.client = createClient({
137+
url: redisUrl,
137138
...(database !== 0 ? { database } : {}),
138-
url: redis_url,
139139
...(socketOptions ? { socket: socketOptions } : {}),
140140
...(clientOptions || {}),
141141
});

src/SyncedMap.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,23 +206,28 @@ export class SyncedMap<V> {
206206
});
207207

208208
// Check if keyspace event configuration is set correctly
209-
const keyspaceEventConfig = (
210-
await this.subscriberClient.configGet('notify-keyspace-events')
211-
)?.['notify-keyspace-events'];
212-
if (!keyspaceEventConfig.includes('E')) {
213-
throw new Error(
214-
"Keyspace event configuration has to include 'E' for Keyevent events, published with __keyevent@<db>__ prefix. We recommend to set it to 'Exe' like so `redis-cli -h localhost config set notify-keyspace-events Exe`",
215-
);
216-
}
217209
if (
218-
!keyspaceEventConfig.includes('A') &&
219-
!(
220-
keyspaceEventConfig.includes('x') && keyspaceEventConfig.includes('e')
221-
)
210+
(process.env.SKIP_KEYSPACE_CONFIG_CHECK || '').toUpperCase() !== 'TRUE'
222211
) {
223-
throw new Error(
224-
"Keyspace event configuration has to include 'A' or 'x' and 'e' for expired and evicted events. We recommend to set it to 'Exe' like so `redis-cli -h localhost config set notify-keyspace-events Exe`",
225-
);
212+
const keyspaceEventConfig = (
213+
await this.subscriberClient.configGet('notify-keyspace-events')
214+
)?.['notify-keyspace-events'];
215+
if (!keyspaceEventConfig.includes('E')) {
216+
throw new Error(
217+
"Keyspace event configuration has to include 'E' for Keyevent events, published with __keyevent@<db>__ prefix. We recommend to set it to 'Exe' like so `redis-cli -h localhost config set notify-keyspace-events Exe`",
218+
);
219+
}
220+
if (
221+
!keyspaceEventConfig.includes('A') &&
222+
!(
223+
keyspaceEventConfig.includes('x') &&
224+
keyspaceEventConfig.includes('e')
225+
)
226+
) {
227+
throw new Error(
228+
"Keyspace event configuration has to include 'A' or 'x' and 'e' for expired and evicted events. We recommend to set it to 'Exe' like so `redis-cli -h localhost config set notify-keyspace-events Exe`",
229+
);
230+
}
226231
}
227232

228233
await Promise.all([

0 commit comments

Comments
 (0)