Skip to content

Commit 3002c0b

Browse files
committed
Cleanup
1 parent bf636f8 commit 3002c0b

File tree

7 files changed

+33
-58
lines changed

7 files changed

+33
-58
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

packages/nextjs-cache-handler/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/nextjs-cache-handler/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
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",
@@ -61,9 +61,6 @@
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
],

packages/nextjs-cache-handler/src/handlers/redis-cluster-strings.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/nextjs-cache-handler/src/handlers/redis-cluster-strings.types.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/nextjs-cache-handler/src/handlers/redis-strings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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) {

packages/nextjs-cache-handler/src/helpers/redisClusterProxy.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import type { RedisClusterType } from "@redis/client";
22
import { 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

99
export 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
}

0 commit comments

Comments
 (0)