@@ -116,13 +116,48 @@ A Redis-based handler for key- and tag-based caching. Compared to the original i
116
116
import createRedisHandler from " @fortedigital/nextjs-cache-handler/redis-strings" ;
117
117
118
118
const redisHandler = await createRedisHandler ({
119
- client,
119
+ client: createClient ({
120
+ url: process .env .REDIS_URL ,
121
+ }),
120
122
keyPrefix: " myApp:" ,
121
123
sharedTagsKey: " myTags" ,
122
124
sharedTagsTtlKey: " myTagTtls" ,
123
125
});
124
126
```
125
127
128
+ #### Redis Cluster (Experimental)
129
+
130
+ ``` js
131
+ import { createCluster } from " @redis/client" ;
132
+ import createRedisHandler from " @fortedigital/nextjs-cache-handler/redis-strings" ;
133
+ import { withAdapter } from " @fortedigital/nextjs-cache-handler/cluster/adapter" ;
134
+
135
+ const { hostname: redisHostName } = new URL (process .env .REDIS_URL );
136
+ redis = withAdapter (
137
+ createCluster ({
138
+ rootNodes: [{ url: process .env .REDIS_URL }],
139
+
140
+ // optional if you use TLS and need to resolve shards' ip to proper hostname
141
+ nodeAddressMap (address ) {
142
+ const [_ , port ] = address .split (" :" );
143
+
144
+ return {
145
+ host: redisHostName,
146
+ port: Number (port),
147
+ };
148
+ },
149
+ })
150
+ );
151
+
152
+ // after using withAdapter you can use redis cluster instance as parameter for createRedisHandler
153
+ const redisCacheHandler = createRedisHandler ({
154
+ client: redis,
155
+ keyPrefix: CACHE_PREFIX ,
156
+ });
157
+ ```
158
+
159
+ ** Note:** Redis Cluster support is currently experimental and may have limitations or unexpected bugs. Use it with caution.
160
+
126
161
---
127
162
128
163
### ` local-lru `
@@ -186,7 +221,8 @@ Next 15 decided to change types of some properties from String to Buffer which c
186
221
` ` ` js
187
222
import createBufferStringDecoratorHandler from " @fortedigital/nextjs-cache-handler/buffer-string-decorator" ;
188
223
189
- const bufferStringDecorator = createBufferStringDecoratorHandler (redisCacheHandler);
224
+ const bufferStringDecorator =
225
+ createBufferStringDecoratorHandler (redisCacheHandler);
190
226
` ` `
191
227
192
228
## Examples
0 commit comments