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({
121
121
});
122
122
```
123
123
124
- ---
125
-
126
- ### ` redis-cluster-strings `
127
-
128
- Same as ` redis-strings ` but for a Redis cluster using ` createCluster ` .
124
+ #### Redis Cluster
129
125
130
126
``` 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" ;
132
130
133
- const redisHandler = await createRedisClusterHandler ({
134
- client: createCluster ({
131
+ const { hostname: redisHostName } = new URL (process .env .REDIS_URL );
132
+ redis = withProxy (
133
+ createCluster ({
135
134
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 ,
140
152
});
141
153
```
142
154
Original file line number Diff line number Diff line change 18
18
" next" ,
19
19
" redis"
20
20
],
21
- "version" : " 2.1.0-canary3 " ,
21
+ "version" : " 2.1.0-canary4 " ,
22
22
"type" : " module" ,
23
23
"license" : " MIT" ,
24
24
"description" : " Next.js cache handlers" ,
61
61
"local-lru" : [
62
62
" dist/handlers/local-lru.d.ts"
63
63
],
64
- "redis-cluster-strings" : [
65
- " dist/handlers/redis-cluster-strings.d.ts"
66
- ],
67
64
"cluster/withProxy" : [
68
65
" dist/helpers/redisClusterProxy.d.ts"
69
66
],
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({
33
33
keyExpirationStrategy = "EXPIREAT" ,
34
34
revalidateTagQuerySize = 10_000 ,
35
35
} : CreateRedisStringsHandlerOptions <
36
- RedisClientType | RedisClusterWithAbortSignal < RedisClusterType >
36
+ RedisClientType | RedisClusterWithAbortSignal
37
37
> ) : Handler {
38
38
function assertClientIsReady ( ) : void {
39
39
if ( ! client . isReady ) {
Original file line number Diff line number Diff line change 1
1
import type { RedisClusterType } from "@redis/client" ;
2
2
import { withAbortSignal } from "./withAbortSignal" ;
3
3
4
- export type RedisClusterWithAbortSignal < T extends RedisClusterType > = T & {
5
- withAbortSignal ( signal : AbortSignal ) : T ;
4
+ export type RedisClusterWithAbortSignal = RedisClusterType & {
5
+ withAbortSignal ( signal : AbortSignal ) : RedisClusterType ;
6
6
isReady : boolean ;
7
7
} ;
8
8
9
9
export function withProxy < T extends RedisClusterType > (
10
- cluster : T ,
10
+ cluster : RedisClusterType ,
11
11
defaultSignal ?: AbortSignal ,
12
- ) : RedisClusterWithAbortSignal < T > {
12
+ ) : RedisClusterWithAbortSignal {
13
13
let signal : AbortSignal | undefined = defaultSignal ;
14
14
15
15
const handler : ProxyHandler < T > = {
@@ -34,5 +34,5 @@ export function withProxy<T extends RedisClusterType>(
34
34
} ,
35
35
} ;
36
36
37
- return new Proxy ( cluster , handler ) as RedisClusterWithAbortSignal < T > ;
37
+ return new Proxy ( cluster , handler ) as RedisClusterWithAbortSignal ;
38
38
}
You can’t perform that action at this time.
0 commit comments