Skip to content

Commit

Permalink
fix: map batch length to length in pipeline.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrunberg committed Sep 18, 2023
1 parent 1259f10 commit 335ef03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class Pipeline {
this._transactions = 0

this.copyCommands()

Object.defineProperty(this, 'length', {
get () {
return this.batch.length;
},
});
}

copyCommands() {
Expand Down
11 changes: 11 additions & 0 deletions test/integration/multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ describe('multi', () => {
expect(redis.batch.batch[1]).toEqual(expect.any(Function))
})

it('should map batch length to length in pipeline',() => {
const redis = new Redis()
const pipeline = redis.pipeline()

pipeline
.incr('user_next')
.incr('post_next');

expect(pipeline.length).toBe(2);
})

it('allows for pipelining methods', () => {
const redis = new Redis()

Expand Down

0 comments on commit 335ef03

Please sign in to comment.