Skip to content

Commit

Permalink
fix(xrange): handle full ids (#1094)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjh0502 authored Nov 3, 2021
1 parent 3ebe0a6 commit ca81ada
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/commands/xrange.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export function xrange(stream, start, end, ...args) {

const list = this.data.get(stream);

const min = start === '-' ? -Infinity : start;
const max = end === '+' ? Infinity : end;
const min = start === '-' ? -Infinity : parseInt(start.split('-')[0], 10);
const max = end === '+' ? Infinity : parseInt(end.split('-')[0], 10);

const result = list.filter(
([eventId]) => min <= parseInt(eventId, 10) && max >= parseInt(eventId, 10)
Expand Down
21 changes: 21 additions & 0 deletions test/commands/xrange.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ describe('xrange', () => {
});
});

it('should handle full id', () => {
const redis = new Redis({
data: {
stream: [
['1-0', ['key', 'val']],
['2-0', ['key', 'val']],
['3-0', ['key', 'val']],
],
'stream:stream:1-0': { polled: false },
'stream:stream:2-0': { polled: false },
'stream:stream:3-0': { polled: false },
},
});
return redis.xrange('stream', '2-0', '+').then((events) => {
expect(events).toEqual([
['2-0', ['key', 'val']],
['3-0', ['key', 'val']],
]);
});
});

it('should throw with a wrong number of arguments', () => {
const redis = new Redis();
Promise.all([
Expand Down

0 comments on commit ca81ada

Please sign in to comment.