Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update zscan's options #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ScanStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface Options extends ReadableOptions {
key?: string;
match?: string;
type?: string;
noscores?: boolean;
command: string;
redis: any;
count?: string | number;
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export interface ScanStreamOptions {
match?: string;
type?: string;
count?: number;
noscores?: boolean;
}
64 changes: 64 additions & 0 deletions lib/utils/RedisCommander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13798,32 +13798,94 @@ interface RedisCommander<Context extends ClientContext = { type: "default" }> {
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(
key: RedisKey,
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(
key: RedisKey,
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(
key: RedisKey,
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(
Expand All @@ -13833,6 +13895,7 @@ interface RedisCommander<Context extends ClientContext = { type: "default" }> {
pattern: string,
countToken: "COUNT",
count: number | string,
noscoresToken: "noscores",
callback?: Callback<[cursor: string, elements: string[]]>
): Result<[cursor: string, elements: string[]], Context>;
zscanBuffer(
Expand All @@ -13842,6 +13905,7 @@ interface RedisCommander<Context extends ClientContext = { type: "default" }> {
pattern: string,
countToken: "COUNT",
count: number | string,
noscoresToken: "noscores",
callback?: Callback<[cursor: Buffer, elements: Buffer[]]>
): Result<[cursor: Buffer, elements: Buffer[]], Context>;

Expand Down
4 changes: 2 additions & 2 deletions test/functional/scripting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions test/unit/commander.ts
Original file line number Diff line number Diff line change
@@ -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()", () => {
Expand Down Expand Up @@ -63,4 +64,20 @@ 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();
}
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();
});
});
});