Skip to content

Commit c8231a2

Browse files
committed
Added cluster support. Exported proxy and abort signal helper
1 parent b53cdd2 commit c8231a2

File tree

10 files changed

+345
-311
lines changed

10 files changed

+345
-311
lines changed

README.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,34 @@ const redisHandler = await createRedisHandler({
121121
});
122122
```
123123

124-
---
125-
126-
### `redis-cluster-strings`
127-
128-
Same as `redis-strings` but for a Redis cluster using `createCluster`.
124+
#### Redis Cluster
129125

130126
```js
131-
import createRedisClusterHandler from "@fortedigital/nextjs-cache-handler/redis-cluster-strings";
127+
import { createCluster } from "@redis/client";
128+
import createRedisHandler from "@fortedigital/nextjs-cache-handler/redis-strings";
129+
import { withProxy } from "@fortedigital/nextjs-cache-handler/cluster/withProxy";
132130

133-
const redisHandler = await createRedisClusterHandler({
134-
client: createCluster({
131+
const { hostname: redisHostName } = new URL(process.env.REDIS_URL);
132+
redis = withProxy(
133+
createCluster({
135134
rootNodes: [{ url: process.env.REDIS_URL }],
136-
}),
137-
keyPrefix: "myApp:",
138-
sharedTagsKey: "myTags",
139-
sharedTagsTtlKey: "myTagTtls",
135+
136+
// optional if you use TLS and need to resolve shards' ip to proper hostname
137+
nodeAddressMap(address) {
138+
const [_, port] = address.split(":");
139+
140+
return {
141+
host: redisHostName,
142+
port: Number(port),
143+
};
144+
},
145+
})
146+
);
147+
148+
// after using withProx you can use redis cluster instance as parameter for createRedisHandler
149+
const redisCacheHandler = createRedisHandler({
150+
client: redis,
151+
keyPrefix: CACHE_PREFIX,
140152
});
141153
```
142154

examples/redis-minimal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"@types/node": "^24",
2626
"@types/react": "^19",
2727
"@types/react-dom": "^19",
28-
"eslint": "^9",
28+
"eslint": "^9",
2929
"eslint-config-next": "15.4.3",
3030
"tailwindcss": "^4",
3131
"typescript": "^5"

0 commit comments

Comments
 (0)