Skip to content

Commit 9f290eb

Browse files
authored
2.1.0
2 parents 56e5235 + 0da8a3b commit 9f290eb

25 files changed

+6721
-2584
lines changed

README.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,48 @@ A Redis-based handler for key- and tag-based caching. Compared to the original i
116116
import createRedisHandler from "@fortedigital/nextjs-cache-handler/redis-strings";
117117

118118
const redisHandler = await createRedisHandler({
119-
client,
119+
client: createClient({
120+
url: process.env.REDIS_URL,
121+
}),
120122
keyPrefix: "myApp:",
121123
sharedTagsKey: "myTags",
122124
sharedTagsTtlKey: "myTagTtls",
123125
});
124126
```
125127

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+
126161
---
127162

128163
### `local-lru`
@@ -186,7 +221,8 @@ Next 15 decided to change types of some properties from String to Buffer which c
186221
```js
187222
import createBufferStringDecoratorHandler from "@fortedigital/nextjs-cache-handler/buffer-string-decorator";
188223

189-
const bufferStringDecorator = createBufferStringDecoratorHandler(redisCacheHandler);
224+
const bufferStringDecorator =
225+
createBufferStringDecoratorHandler(redisCacheHandler);
190226
```
191227
192228
## Examples

examples/redis-minimal/next.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ const nextConfig: NextConfig = {
66
? require.resolve("./cache-handler.mjs")
77
: undefined,
88
cacheMaxMemorySize: 0, // disable default in-memory caching
9+
experimental: {
10+
//ppr: "incremental",
11+
},
912
};
1013

1114
export default nextConfig;

0 commit comments

Comments
 (0)