From 28fb55709055aca3cc0078f9e2d919111b2babb7 Mon Sep 17 00:00:00 2001 From: Nicolas Zambrano Date: Tue, 7 Jan 2025 10:49:27 +0100 Subject: [PATCH 1/3] feat(HscanStream): adding NOVALUES option --- README.md | 8 +++++++- lib/ScanStream.ts | 5 ++++- lib/types.ts | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9881f3ce..526502a8 100644 --- a/README.md +++ b/README.md @@ -722,12 +722,18 @@ the key names are not utf8 strings. There are also `hscanStream`, `zscanStream` and `sscanStream` to iterate through elements in a hash, zset and set. The interface of each is similar to `scanStream` except the first argument is the key name: +```javascript +const stream = redis.zscanStream("myhash", { + match: "age:??", +}); +``` +Also `hscanStream` accept noValues option (true or false) ```javascript const stream = redis.hscanStream("myhash", { match: "age:??", + noValues: true, }); ``` - You can learn more from the [Redis documentation](http://redis.io/commands/scan). **Useful Tips** diff --git a/lib/ScanStream.ts b/lib/ScanStream.ts index e74a7a2c..46816753 100644 --- a/lib/ScanStream.ts +++ b/lib/ScanStream.ts @@ -7,6 +7,7 @@ interface Options extends ReadableOptions { command: string; redis: any; count?: string | number; + noValues?: boolean; } /** @@ -39,7 +40,9 @@ export default class ScanStream extends Readable { if (this.opt.count) { args.push("COUNT", String(this.opt.count)); } - + if (this.opt.noValues) { + args.push("NOVALUES"); + } this.opt.redis[this.opt.command](args, (err, res) => { if (err) { this.emit("error", err); diff --git a/lib/types.ts b/lib/types.ts index 8c897a8e..34b0a421 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -30,4 +30,5 @@ export interface ScanStreamOptions { match?: string; type?: string; count?: number; -} + noValues?: boolean; +} \ No newline at end of file From 2164d81863eb39d672063376a38a9764bdb34789 Mon Sep 17 00:00:00 2001 From: Nicolas Zambrano Date: Tue, 7 Jan 2025 12:15:26 +0100 Subject: [PATCH 2/3] fix(Test): adding tests for NOVALUES option --- test/functional/scan_stream.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/functional/scan_stream.ts b/test/functional/scan_stream.ts index 2ea17108..378e07df 100644 --- a/test/functional/scan_stream.ts +++ b/test/functional/scan_stream.ts @@ -161,6 +161,25 @@ describe("*scanStream", () => { }); }); + describe('hscanStream', () => { + it('should recognize `NOVALUES`', (done) => { + let keys = []; + const redis = new Redis(); + redis.hset('object', 'foo1', 'foo1_value'); + redis.hset('object', 'foo2', 'foo2_value'); + redis.hset('object', 'foo3', 'foo3_value'); + const stream = redis.hscanStream('object', { noValues: true }); + stream.on('data', function (data) { + keys = keys.concat(data); + }); + stream.on('end', () => { + expect(keys).to.eql(['foo1', 'foo2', 'foo3']); + redis.disconnect(); + done(); + }); + }); + }); + describe("Cluster", () => { it("should work in cluster mode", (done) => { const slotTable = [ From e5802a152860602bc48ba0b9c6367bfee891b3c6 Mon Sep 17 00:00:00 2001 From: Nicolas Zambrano Date: Sat, 25 Jan 2025 10:32:18 +0100 Subject: [PATCH 3/3] Update README.md for hscanStream Co-authored-by: Tihomir Krasimirov Mateev --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 526502a8..a25e0609 100644 --- a/README.md +++ b/README.md @@ -727,7 +727,7 @@ const stream = redis.zscanStream("myhash", { match: "age:??", }); ``` -Also `hscanStream` accept noValues option (true or false) +The `hscanStream` also accepts the `noValues` option to specify whether Redis should return only the keys in the hash table without their corresponding values. ```javascript const stream = redis.hscanStream("myhash", { match: "age:??",