Skip to content

Commit 9505d6b

Browse files
authored
feat: update zscan's options (#12)
* feat: update zscan Signed-off-by: jhpung <[email protected]> * test: add zscan tests Signed-off-by: jhpung <[email protected]> * fix: update script error message Signed-off-by: jhpung <[email protected]> * test(scripting): change expect assertions from .equal to .match Signed-off-by: jhpung <[email protected]> --------- Signed-off-by: jhpung <[email protected]>
1 parent 128c428 commit 9505d6b

File tree

5 files changed

+88
-6
lines changed

5 files changed

+88
-6
lines changed

lib/ScanStream.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ interface Options extends ReadableOptions {
44
key?: string;
55
match?: string;
66
type?: string;
7+
noscores?: boolean;
78
command: string;
89
redis: any;
910
count?: string | number;
@@ -39,6 +40,9 @@ export default class ScanStream extends Readable {
3940
if (this.opt.count) {
4041
args.push("COUNT", String(this.opt.count));
4142
}
43+
if (this.opt.noscores) {
44+
args.push("noscores");
45+
}
4246

4347
this.opt.redis[this.opt.command](args, (err, res) => {
4448
if (err) {

lib/types.ts

Lines changed: 1 addition & 0 deletions
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+
noscores?: boolean;
3334
}

lib/utils/RedisCommander.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13798,32 +13798,94 @@ interface RedisCommander<Context extends ClientContext = { type: "default" }> {
1379813798
cursor: number | string,
1379913799
callback?: Callback<[cursor: Buffer, elements: Buffer[]]>
1380013800
): Result<[cursor: Buffer, elements: Buffer[]], Context>;
13801+
zscan(
13802+
key: RedisKey,
13803+
cursor: number | string,
13804+
noscoresToken: "noscores",
13805+
callback?: Callback<[cursor: string, elements: string[]]>
13806+
): Result<[cursor: string, elements: string[]], Context>;
13807+
zscanBuffer(
13808+
key: RedisKey,
13809+
cursor: number | string,
13810+
noscoresToken: "noscores",
13811+
callback?: Callback<[cursor: Buffer, elements: Buffer[]]>
13812+
): Result<[cursor: Buffer, elements: Buffer[]], Context>;
13813+
zscan(
13814+
key: RedisKey,
13815+
cursor: number | string,
13816+
countToken: "COUNT",
13817+
count: number | string,
13818+
callback?: Callback<[cursor: string, elements: string[]]>
13819+
): Result<[cursor: string, elements: string[]], Context>;
13820+
zscanBuffer(
13821+
key: RedisKey,
13822+
cursor: number | string,
13823+
countToken: "COUNT",
13824+
count: number | string,
13825+
callback?: Callback<[cursor: Buffer, elements: Buffer[]]>
13826+
): Result<[cursor: Buffer, elements: Buffer[]], Context>;
1380113827
zscan(
1380213828
key: RedisKey,
1380313829
cursor: number | string,
1380413830
countToken: "COUNT",
1380513831
count: number | string,
13832+
noscoresToken: "noscores",
1380613833
callback?: Callback<[cursor: string, elements: string[]]>
1380713834
): Result<[cursor: string, elements: string[]], Context>;
1380813835
zscanBuffer(
1380913836
key: RedisKey,
1381013837
cursor: number | string,
1381113838
countToken: "COUNT",
1381213839
count: number | string,
13840+
noscoresToken: "noscores",
13841+
callback?: Callback<[cursor: Buffer, elements: Buffer[]]>
13842+
): Result<[cursor: Buffer, elements: Buffer[]], Context>;
13843+
zscan(
13844+
key: RedisKey,
13845+
cursor: number | string,
13846+
patternToken: "MATCH",
13847+
pattern: string,
13848+
callback?: Callback<[cursor: string, elements: string[]]>
13849+
): Result<[cursor: string, elements: string[]], Context>;
13850+
zscanBuffer(
13851+
key: RedisKey,
13852+
cursor: number | string,
13853+
patternToken: "MATCH",
13854+
pattern: string,
13855+
callback?: Callback<[cursor: Buffer, elements: Buffer[]]>
13856+
): Result<[cursor: Buffer, elements: Buffer[]], Context>;
13857+
zscan(
13858+
key: RedisKey,
13859+
cursor: number | string,
13860+
patternToken: "MATCH",
13861+
pattern: string,
13862+
noscoresToken: "noscores",
13863+
callback?: Callback<[cursor: string, elements: string[]]>
13864+
): Result<[cursor: string, elements: string[]], Context>;
13865+
zscanBuffer(
13866+
key: RedisKey,
13867+
cursor: number | string,
13868+
patternToken: "MATCH",
13869+
pattern: string,
13870+
noscoresToken: "noscores",
1381313871
callback?: Callback<[cursor: Buffer, elements: Buffer[]]>
1381413872
): Result<[cursor: Buffer, elements: Buffer[]], Context>;
1381513873
zscan(
1381613874
key: RedisKey,
1381713875
cursor: number | string,
1381813876
patternToken: "MATCH",
1381913877
pattern: string,
13878+
countToken: "COUNT",
13879+
count: number | string,
1382013880
callback?: Callback<[cursor: string, elements: string[]]>
1382113881
): Result<[cursor: string, elements: string[]], Context>;
1382213882
zscanBuffer(
1382313883
key: RedisKey,
1382413884
cursor: number | string,
1382513885
patternToken: "MATCH",
1382613886
pattern: string,
13887+
countToken: "COUNT",
13888+
count: number | string,
1382713889
callback?: Callback<[cursor: Buffer, elements: Buffer[]]>
1382813890
): Result<[cursor: Buffer, elements: Buffer[]], Context>;
1382913891
zscan(
@@ -13833,6 +13895,7 @@ interface RedisCommander<Context extends ClientContext = { type: "default" }> {
1383313895
pattern: string,
1383413896
countToken: "COUNT",
1383513897
count: number | string,
13898+
noscoresToken: "noscores",
1383613899
callback?: Callback<[cursor: string, elements: string[]]>
1383713900
): Result<[cursor: string, elements: string[]], Context>;
1383813901
zscanBuffer(
@@ -13842,6 +13905,7 @@ interface RedisCommander<Context extends ClientContext = { type: "default" }> {
1384213905
pattern: string,
1384313906
countToken: "COUNT",
1384413907
count: number | string,
13908+
noscoresToken: "noscores",
1384513909
callback?: Callback<[cursor: Buffer, elements: Buffer[]]>
1384613910
): Result<[cursor: Buffer, elements: Buffer[]], Context>;
1384713911

test/functional/scripting.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,8 @@ describe("scripting", () => {
250250
// @ts-expect-error
251251
const [a, b] = await redis.multi().test("foo").test("bar").exec();
252252

253-
expect(a[0].message).to.equal(
254-
"NOSCRIPT No matching script. Please use EVAL."
255-
);
256-
expect(b[0].message).to.equal(
257-
"NOSCRIPT No matching script. Please use EVAL."
258-
);
253+
expect(a[0].message).to.match(/^NOSCRIPT No matching script/);
254+
expect(b[0].message).to.match(/^NOSCRIPT No matching script/);
259255
});
260256
spy.restore();
261257
expect(spy.callCount).to.equal(4);

test/unit/commander.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as sinon from "sinon";
22
import { expect } from "chai";
33
import Commander from "../../lib/utils/Commander";
4+
import Command from "../../lib/Command";
45

56
describe("Commander", () => {
67
describe("#getBuiltinCommands()", () => {
@@ -63,4 +64,20 @@ describe("Commander", () => {
6364

6465
Commander.prototype.sendCommand.restore();
6566
});
67+
68+
describe("#zscan", () => {
69+
it("should pass noscores option", async (done) => {
70+
const args: any[] = ["key", "0", "MATCH", "pattern", "COUNT", "10", "noscores"];
71+
sinon.stub(Commander.prototype, "sendCommand").callsFake((command) => {
72+
if(command.args.every((arg, index) => arg === args[index])) {
73+
return done();
74+
}
75+
return done(new Error(`args should be ${args.join(", ")}`));
76+
});
77+
const c = new Commander();
78+
79+
await c.zscan(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
80+
(Commander.prototype.sendCommand as any).restore();
81+
});
82+
});
6683
});

0 commit comments

Comments
 (0)