From 335ef03890ae85449d3afde1500a95f10e7a9890 Mon Sep 17 00:00:00 2001 From: Matias Grunberg Date: Mon, 18 Sep 2023 15:35:13 -0300 Subject: [PATCH] fix: map batch length to length in pipeline.js --- src/pipeline.js | 6 ++++++ test/integration/multi.js | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/pipeline.js b/src/pipeline.js index 503773772..01d1212c8 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 8c6dc1cb6..e0cc118cc 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()