Skip to content

Commit d2d635d

Browse files
fix: ensure CSR works with a Redis cluster
The pipeline with the XRANGE and GETDEL commands could throw: > CROSSSLOT Keys in request don't hash to the same slot when ran against a Redis cluster.
1 parent 418ff5e commit d2d635d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/adapter.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,17 @@ class RedisStreamsAdapter extends ClusterAdapterWithHeartbeat {
252252

253253
const sessionKey = this.#opts.sessionKeyPrefix + pid;
254254

255-
const [rawSession, offsetExists] = await this.#redisClient
256-
.multi()
257-
.get(sessionKey)
258-
.del(sessionKey) // GETDEL was added in Redis version 6.2
259-
.xRange(this.#opts.streamName, offset, offset)
260-
.exec();
255+
const results = await Promise.all([
256+
this.#redisClient
257+
.multi()
258+
.get(sessionKey)
259+
.del(sessionKey) // GETDEL was added in Redis version 6.2
260+
.exec(),
261+
this.#redisClient.xRange(this.#opts.streamName, offset, offset),
262+
]);
263+
264+
const rawSession = results[0][0];
265+
const offsetExists = results[1][0];
261266

262267
if (!rawSession || !offsetExists) {
263268
return Promise.reject("session or offset not found");

0 commit comments

Comments
 (0)