File tree Expand file tree Collapse file tree 7 files changed +33
-58
lines changed
packages/nextjs-cache-handler Expand file tree Collapse file tree 7 files changed +33
-58
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1818 " next" ,
1919 " redis"
2020 ],
21- "version" : " 2.1.0-canary3 " ,
21+ "version" : " 2.1.0-canary4 " ,
2222 "type" : " module" ,
2323 "license" : " MIT" ,
2424 "description" : " Next.js cache handlers" ,
6161 "local-lru" : [
6262 " dist/handlers/local-lru.d.ts"
6363 ],
64- "redis-cluster-strings" : [
65- " dist/handlers/redis-cluster-strings.d.ts"
66- ],
6764 "cluster/withProxy" : [
6865 " dist/helpers/redisClusterProxy.d.ts"
6966 ],
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ export default function createHandler({
3333 keyExpirationStrategy = "EXPIREAT" ,
3434 revalidateTagQuerySize = 10_000 ,
3535} : CreateRedisStringsHandlerOptions <
36- RedisClientType | RedisClusterWithAbortSignal < RedisClusterType >
36+ RedisClientType | RedisClusterWithAbortSignal
3737> ) : Handler {
3838 function assertClientIsReady ( ) : void {
3939 if ( ! client . isReady ) {
Original file line number Diff line number Diff line change 11import type { RedisClusterType } from "@redis/client" ;
22import { withAbortSignal } from "./withAbortSignal" ;
33
4- export type RedisClusterWithAbortSignal < T extends RedisClusterType > = T & {
5- withAbortSignal ( signal : AbortSignal ) : T ;
4+ export type RedisClusterWithAbortSignal = RedisClusterType & {
5+ withAbortSignal ( signal : AbortSignal ) : RedisClusterType ;
66 isReady : boolean ;
77} ;
88
99export function withProxy < T extends RedisClusterType > (
10- cluster : T ,
10+ cluster : RedisClusterType ,
1111 defaultSignal ?: AbortSignal ,
12- ) : RedisClusterWithAbortSignal < T > {
12+ ) : RedisClusterWithAbortSignal {
1313 let signal : AbortSignal | undefined = defaultSignal ;
1414
1515 const handler : ProxyHandler < T > = {
@@ -34,5 +34,5 @@ export function withProxy<T extends RedisClusterType>(
3434 } ,
3535 } ;
3636
37- return new Proxy ( cluster , handler ) as RedisClusterWithAbortSignal < T > ;
37+ return new Proxy ( cluster , handler ) as RedisClusterWithAbortSignal ;
3838}
You can’t perform that action at this time.
0 commit comments