Skip to content

Commit

Permalink
fix: map batch length to length in pipeline (#1201)
Browse files Browse the repository at this point in the history
Fixes #1046
  • Loading branch information
j1gs4w authored Jan 29, 2023
1 parent 9213bc7 commit a4e8a4a
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 @@ -10,6 +10,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 a4e8a4a

Please sign in to comment.