diff --git a/lib/ScanStream.ts b/lib/ScanStream.ts index e74a7a2c..c6091b92 100644 --- a/lib/ScanStream.ts +++ b/lib/ScanStream.ts @@ -4,6 +4,7 @@ interface Options extends ReadableOptions { key?: string; match?: string; type?: string; + noscores?: boolean; command: string; redis: any; count?: string | number; @@ -39,6 +40,9 @@ export default class ScanStream extends Readable { if (this.opt.count) { args.push("COUNT", String(this.opt.count)); } + if (this.opt.noscores) { + args.push("noscores"); + } this.opt.redis[this.opt.command](args, (err, res) => { if (err) { diff --git a/lib/types.ts b/lib/types.ts index 8c897a8e..37821ae5 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -30,4 +30,5 @@ export interface ScanStreamOptions { match?: string; type?: string; count?: number; + noscores?: boolean; } diff --git a/lib/utils/RedisCommander.ts b/lib/utils/RedisCommander.ts index 49388d8e..215ed50b 100644 --- a/lib/utils/RedisCommander.ts +++ b/lib/utils/RedisCommander.ts @@ -13798,11 +13798,38 @@ interface RedisCommander { cursor: number | string, callback?: Callback<[cursor: Buffer, elements: Buffer[]]> ): Result<[cursor: Buffer, elements: Buffer[]], Context>; + zscan( + key: RedisKey, + cursor: number | string, + noscoresToken: "noscores", + callback?: Callback<[cursor: string, elements: string[]]> + ): Result<[cursor: string, elements: string[]], Context>; + zscanBuffer( + key: RedisKey, + cursor: number | string, + noscoresToken: "noscores", + callback?: Callback<[cursor: Buffer, elements: Buffer[]]> + ): Result<[cursor: Buffer, elements: Buffer[]], Context>; + zscan( + key: RedisKey, + cursor: number | string, + countToken: "COUNT", + count: number | string, + callback?: Callback<[cursor: string, elements: string[]]> + ): Result<[cursor: string, elements: string[]], Context>; + zscanBuffer( + key: RedisKey, + cursor: number | string, + countToken: "COUNT", + count: number | string, + callback?: Callback<[cursor: Buffer, elements: Buffer[]]> + ): Result<[cursor: Buffer, elements: Buffer[]], Context>; zscan( key: RedisKey, cursor: number | string, countToken: "COUNT", count: number | string, + noscoresToken: "noscores", callback?: Callback<[cursor: string, elements: string[]]> ): Result<[cursor: string, elements: string[]], Context>; zscanBuffer( @@ -13810,6 +13837,37 @@ interface RedisCommander { cursor: number | string, countToken: "COUNT", count: number | string, + noscoresToken: "noscores", + callback?: Callback<[cursor: Buffer, elements: Buffer[]]> + ): Result<[cursor: Buffer, elements: Buffer[]], Context>; + zscan( + key: RedisKey, + cursor: number | string, + patternToken: "MATCH", + pattern: string, + callback?: Callback<[cursor: string, elements: string[]]> + ): Result<[cursor: string, elements: string[]], Context>; + zscanBuffer( + key: RedisKey, + cursor: number | string, + patternToken: "MATCH", + pattern: string, + callback?: Callback<[cursor: Buffer, elements: Buffer[]]> + ): Result<[cursor: Buffer, elements: Buffer[]], Context>; + zscan( + key: RedisKey, + cursor: number | string, + patternToken: "MATCH", + pattern: string, + noscoresToken: "noscores", + callback?: Callback<[cursor: string, elements: string[]]> + ): Result<[cursor: string, elements: string[]], Context>; + zscanBuffer( + key: RedisKey, + cursor: number | string, + patternToken: "MATCH", + pattern: string, + noscoresToken: "noscores", callback?: Callback<[cursor: Buffer, elements: Buffer[]]> ): Result<[cursor: Buffer, elements: Buffer[]], Context>; zscan( @@ -13817,6 +13875,8 @@ interface RedisCommander { cursor: number | string, patternToken: "MATCH", pattern: string, + countToken: "COUNT", + count: number | string, callback?: Callback<[cursor: string, elements: string[]]> ): Result<[cursor: string, elements: string[]], Context>; zscanBuffer( @@ -13824,6 +13884,8 @@ interface RedisCommander { cursor: number | string, patternToken: "MATCH", pattern: string, + countToken: "COUNT", + count: number | string, callback?: Callback<[cursor: Buffer, elements: Buffer[]]> ): Result<[cursor: Buffer, elements: Buffer[]], Context>; zscan( @@ -13833,6 +13895,7 @@ interface RedisCommander { pattern: string, countToken: "COUNT", count: number | string, + noscoresToken: "noscores", callback?: Callback<[cursor: string, elements: string[]]> ): Result<[cursor: string, elements: string[]], Context>; zscanBuffer( @@ -13842,6 +13905,7 @@ interface RedisCommander { pattern: string, countToken: "COUNT", count: number | string, + noscoresToken: "noscores", callback?: Callback<[cursor: Buffer, elements: Buffer[]]> ): Result<[cursor: Buffer, elements: Buffer[]], Context>; diff --git a/test/functional/scripting.ts b/test/functional/scripting.ts index ee796bff..60bd86ac 100644 --- a/test/functional/scripting.ts +++ b/test/functional/scripting.ts @@ -251,10 +251,10 @@ describe("scripting", () => { const [a, b] = await redis.multi().test("foo").test("bar").exec(); expect(a[0].message).to.equal( - "NOSCRIPT No matching script. Please use EVAL." + "NOSCRIPT No matching script." ); expect(b[0].message).to.equal( - "NOSCRIPT No matching script. Please use EVAL." + "NOSCRIPT No matching script." ); }); spy.restore(); diff --git a/test/unit/commander.ts b/test/unit/commander.ts index 109cbe6b..f54031fa 100644 --- a/test/unit/commander.ts +++ b/test/unit/commander.ts @@ -1,6 +1,7 @@ import * as sinon from "sinon"; import { expect } from "chai"; import Commander from "../../lib/utils/Commander"; +import Command from "../../lib/Command"; describe("Commander", () => { describe("#getBuiltinCommands()", () => { @@ -63,4 +64,21 @@ describe("Commander", () => { Commander.prototype.sendCommand.restore(); }); + + describe("#zscan", () => { + it("should pass noscores option", async (done) => { + const args: any[] = ["key", "0", "MATCH", "pattern", "COUNT", "10", "noscores"]; + sinon.stub(Commander.prototype, "sendCommand").callsFake((command) => { + if(command.args.every((arg, index) => arg === args[index])) { + return done(); + } + console.error(command.args); + return done(new Error(`args should be ${args.join(", ")}`)); + }); + const c = new Commander(); + + await c.zscan(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + (Commander.prototype.sendCommand as any).restore(); + }); + }); });