connect-redis
Advanced tools
Comparing version
@@ -24,3 +24,4 @@ import { Store } from "express-session"; | ||
normalizeClient(client) { | ||
let isRedis = "scanIterator" in client; | ||
let isRedis = "scanIterator" in client || "masters" in client; | ||
let isRedisCluster = "masters" in client; | ||
return { | ||
@@ -38,2 +39,15 @@ get: (key) => client.get(key), | ||
scanIterator: (match, count) => { | ||
if (isRedisCluster) { | ||
return async function* () { | ||
for (const master of client.masters) { | ||
const nodeClient = await client.nodeClient(master); | ||
for await (const key of nodeClient.scanIterator({ | ||
COUNT: count, | ||
MATCH: match | ||
})) { | ||
yield key; | ||
} | ||
} | ||
}(); | ||
} | ||
if (isRedis) return client.scanIterator({ MATCH: match, COUNT: count }); | ||
@@ -40,0 +54,0 @@ return async function* () { |
@@ -9,2 +9,3 @@ import js from "@eslint/js" | ||
"prefer-const": 0, | ||
eqeqeq: [2, "smart"], | ||
"@typescript-eslint/no-explicit-any": 0, | ||
@@ -11,0 +12,0 @@ "@typescript-eslint/no-unused-vars": [ |
20
index.ts
@@ -51,3 +51,5 @@ import {SessionData, Store} from "express-session" | ||
private normalizeClient(client: any): NormalizedRedisClient { | ||
let isRedis = "scanIterator" in client | ||
let isRedis = "scanIterator" in client || "masters" in client | ||
let isRedisCluster = "masters" in client | ||
return { | ||
@@ -67,2 +69,18 @@ get: (key) => client.get(key), | ||
scanIterator: (match, count) => { | ||
// node-redis createCluster impl. | ||
if (isRedisCluster) { | ||
return (async function* () { | ||
for (const master of client.masters) { | ||
const nodeClient = await client.nodeClient(master) | ||
for await (const key of nodeClient.scanIterator({ | ||
COUNT: count, | ||
MATCH: match, | ||
})) { | ||
yield key | ||
} | ||
} | ||
})() | ||
} | ||
if (isRedis) return client.scanIterator({MATCH: match, COUNT: count}) | ||
@@ -69,0 +87,0 @@ |
{ | ||
"name": "connect-redis", | ||
"description": "Redis session store for Connect", | ||
"version": "8.0.2", | ||
"version": "8.0.3", | ||
"author": "TJ Holowaychuk <tj@vision-media.ca>", | ||
@@ -31,20 +31,20 @@ "contributors": [ | ||
"devDependencies": { | ||
"@eslint/js": "^9.21.0", | ||
"@eslint/js": "^9.24.0", | ||
"@types/express-session": "^1.18.1", | ||
"@types/node": "^22.13.5", | ||
"@vitest/coverage-v8": "^3.0.7", | ||
"eslint": "^9.21.0", | ||
"eslint-config-prettier": "^10.0.2", | ||
"eslint-plugin-prettier": "^5.2.3", | ||
"@types/node": "^22.14.1", | ||
"@vitest/coverage-v8": "^3.1.1", | ||
"eslint": "^9.24.0", | ||
"eslint-config-prettier": "^10.1.2", | ||
"eslint-plugin-prettier": "^5.2.6", | ||
"express-session": "^1.18.1", | ||
"ioredis": "^5.5.0", | ||
"prettier": "^3.5.2", | ||
"ioredis": "^5.6.1", | ||
"prettier": "^3.5.3", | ||
"prettier-plugin-organize-imports": "^4.1.0", | ||
"redis": "^4.7.0", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.7.3", | ||
"typescript-eslint": "^8.25.0", | ||
"vite": "^6.2.0", | ||
"vite-plugin-dts": "^4.5.0", | ||
"vitest": "^3.0.7" | ||
"typescript": "^5.8.3", | ||
"typescript-eslint": "^8.30.1", | ||
"vite": "^6.3.1", | ||
"vite-plugin-dts": "^4.5.3", | ||
"vitest": "^3.1.1" | ||
}, | ||
@@ -51,0 +51,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
34541
4.56%782
5.96%