diff --git a/README.md b/README.md index 9881f3ce..a25e0609 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:??", +}); +``` +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:??", + 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 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 = [