Skip to content

Commit d2eeb63

Browse files
committed
fix node-redis cluster normalisation
1 parent 8b51d59 commit d2eeb63

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

index.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ export class RedisStore extends Store {
4848

4949
// Create a redis and ioredis compatible client
5050
private normalizeClient(client: any): NormalizedRedisClient {
51-
let isRedis = "scanIterator" in client
51+
let isRedis = "scanIterator" in client || "masters" in client;
52+
let isRedisCluster = "masters" in client;
53+
5254
return {
5355
get: (key) => client.get(key),
5456
set: (key, val, ttl) => {
@@ -63,6 +65,19 @@ export class RedisStore extends Store {
6365
expire: (key, ttl) => client.expire(key, ttl),
6466
mget: (keys) => (isRedis ? client.mGet(keys) : client.mget(keys)),
6567
scanIterator: (match, count) => {
68+
// node-redis createCluster impl.
69+
if (isRedisCluster) {
70+
return (async function *() {
71+
for (const master of client.masters) {
72+
const nodeClient = await client.nodeClient(master);
73+
74+
for await (const key of nodeClient.scanIterator({ COUNT: count, MATCH: match })) {
75+
yield key;
76+
}
77+
}
78+
})();
79+
}
80+
6681
if (isRedis) return client.scanIterator({MATCH: match, COUNT: count})
6782

6883
// ioredis impl.

0 commit comments

Comments
 (0)