From a6e2a63c21515700b2cb255bb050c22fbab60182 Mon Sep 17 00:00:00 2001 From: Sladuca Date: Wed, 6 Sep 2023 11:42:46 -0400 Subject: [PATCH] fix redis stream id comparison --- packages/persistent-log/src/persistentLog.ts | 2 +- packages/persistent-log/src/redisStreamId.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/persistent-log/src/persistentLog.ts b/packages/persistent-log/src/persistentLog.ts index 5d7029fd47..653bf39ad0 100644 --- a/packages/persistent-log/src/persistentLog.ts +++ b/packages/persistent-log/src/persistentLog.ts @@ -169,7 +169,7 @@ export class PersistentLog { // filter out all data >= `options.endId` if given if (options?.endId !== undefined) { const endId = options.endId; - batch = batch.filter(({ id }) => id < endId); + batch = batch.filter(({ id }) => RedisStreamIdTrait.lt(id, endId)); // if there's no more data after filtering, terminate if (batch.length == 0) { break; diff --git a/packages/persistent-log/src/redisStreamId.ts b/packages/persistent-log/src/redisStreamId.ts index d69c1e163a..ef366b300c 100644 --- a/packages/persistent-log/src/redisStreamId.ts +++ b/packages/persistent-log/src/redisStreamId.ts @@ -40,6 +40,17 @@ export class RedisStreamIdTrait { } return `${Number(lhs)}-${Number(rhs)}`; } + + static lt(lhs: RedisStreamId, rhs: RedisStreamId): boolean { + const [lhsL, lhsR] = RedisStreamIdTrait.toComponents(lhs); + const [rhsL, rhsR] = RedisStreamIdTrait.toComponents(rhs); + + if (lhsL === rhsL) { + return lhsR < rhsR; + } + + return lhsL < rhsL; + } } export interface WithRedisStreamId {