Skip to content

Commit

Permalink
fix redis stream id comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Sladuca committed Sep 6, 2023
1 parent b39b39c commit a6e2a63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/persistent-log/src/persistentLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class PersistentLog<T> {
// 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;
Expand Down
11 changes: 11 additions & 0 deletions packages/persistent-log/src/redisStreamId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
Expand Down

0 comments on commit a6e2a63

Please sign in to comment.