Skip to content

Commit 2f9843d

Browse files
NickZambranoNicolas Zambranotishun
authored
feat(HscanStream): adding NOVALUES option (#1943)
* feat(HscanStream): adding NOVALUES option * fix(Test): adding tests for NOVALUES option * Update README.md for hscanStream Co-authored-by: Tihomir Krasimirov Mateev <[email protected]> --------- Co-authored-by: Nicolas Zambrano <[email protected]> Co-authored-by: Tihomir Krasimirov Mateev <[email protected]>
1 parent 5d3e7ca commit 2f9843d

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,12 +724,18 @@ the key names are not utf8 strings.
724724
There are also `hscanStream`, `zscanStream` and `sscanStream` to iterate through elements in a hash, zset and set. The interface of each is
725725
similar to `scanStream` except the first argument is the key name:
726726

727+
```javascript
728+
const stream = redis.zscanStream("myhash", {
729+
match: "age:??",
730+
});
731+
```
732+
The `hscanStream` also accepts the `noValues` option to specify whether Redis should return only the keys in the hash table without their corresponding values.
727733
```javascript
728734
const stream = redis.hscanStream("myhash", {
729735
match: "age:??",
736+
noValues: true,
730737
});
731738
```
732-
733739
You can learn more from the [Redis documentation](http://redis.io/commands/scan).
734740

735741
**Useful Tips**

lib/ScanStream.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface Options extends ReadableOptions {
77
command: string;
88
redis: any;
99
count?: string | number;
10+
noValues?: boolean;
1011
}
1112

1213
/**
@@ -39,7 +40,9 @@ export default class ScanStream extends Readable {
3940
if (this.opt.count) {
4041
args.push("COUNT", String(this.opt.count));
4142
}
42-
43+
if (this.opt.noValues) {
44+
args.push("NOVALUES");
45+
}
4346
this.opt.redis[this.opt.command](args, (err, res) => {
4447
if (err) {
4548
this.emit("error", err);

lib/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ export interface ScanStreamOptions {
3030
match?: string;
3131
type?: string;
3232
count?: number;
33-
}
33+
noValues?: boolean;
34+
}

test/functional/scan_stream.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,25 @@ describe("*scanStream", () => {
161161
});
162162
});
163163

164+
describe('hscanStream', () => {
165+
it('should recognize `NOVALUES`', (done) => {
166+
let keys = [];
167+
const redis = new Redis();
168+
redis.hset('object', 'foo1', 'foo1_value');
169+
redis.hset('object', 'foo2', 'foo2_value');
170+
redis.hset('object', 'foo3', 'foo3_value');
171+
const stream = redis.hscanStream('object', { noValues: true });
172+
stream.on('data', function (data) {
173+
keys = keys.concat(data);
174+
});
175+
stream.on('end', () => {
176+
expect(keys).to.eql(['foo1', 'foo2', 'foo3']);
177+
redis.disconnect();
178+
done();
179+
});
180+
});
181+
});
182+
164183
describe("Cluster", () => {
165184
it("should work in cluster mode", (done) => {
166185
const slotTable = [

0 commit comments

Comments
 (0)