diff --git a/src/pipeline.js b/src/pipeline.js index 50377377..01d1212c 100644 --- a/src/pipeline.js +++ b/src/pipeline.js @@ -11,6 +11,12 @@ class Pipeline { this._transactions = 0 this.copyCommands() + + Object.defineProperty(this, 'length', { + get () { + return this.batch.length; + }, + }); } copyCommands() { diff --git a/test/integration/multi.js b/test/integration/multi.js index 8c6dc1cb..e0cc118c 100644 --- a/test/integration/multi.js +++ b/test/integration/multi.js @@ -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()