You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
7
7
8
8
Key Features:
9
9
@@ -13,6 +13,8 @@ Key Features:
13
13
-_Efficient Tag Management_: in-memory tags map for lightning-fast revalidate operations with minimal Redis overhead.
14
14
-_Intelligent Key-Space Notifications_: Automatic update of in-memory tags map for expired or evicted keys.
15
15
16
+
This library offers you an easy and high performant caching solution for docker, Kubernetes or Google Cloud Run deployments of Next.js.
17
+
16
18
## Compatibility
17
19
18
20
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.
46
48
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.
47
49
Furthermore there exists the DEBUG_CACHE_HANDLER environment variable to enable debug logging of the caching handler once it is set to true.
48
50
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
+
49
53
### Option A: minimum implementation with default options
50
54
51
55
extend `next.config.js` with:
@@ -117,7 +121,7 @@ A working example of above can be found in the `test/integration/next-app-custom
| database | Redis database number to use. Uses DB 0 for production, DB 1 otherwise |`process.env.VERCEL_ENV === 'production' ? 0 : 1`|
122
126
| keyPrefix | Prefix added to all Redis keys |`process.env.VERCEL_URL \|\| 'UNDEFINED_URL_'`|
123
127
| 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
197
201
198
202
## Testing
199
203
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:
203
205
204
206
```bash
205
-
pnpm test
207
+
pnpm build && pnpm test
206
208
```
207
209
208
210
### Unit tests
209
211
210
212
To run unit tests you can use the following command:
211
213
212
214
```bash
213
-
pnpm test:unit
215
+
pnpm build && pnpm test:unit
214
216
```
215
217
216
218
### Integration tests
217
219
218
220
To run integration tests you can use the following command:
219
221
220
222
```bash
221
-
pnpm test:integration
223
+
pnpm build && pnpm test:integration
222
224
```
223
225
224
226
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:
"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.",
"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`",
"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`",
"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
+
thrownewError(
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`",
0 commit comments