Skip to content

Commit

Permalink
fix(#286): zaddIncr does not work (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
uki00a authored Jan 23, 2022
1 parent 86803df commit b2f4287
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
11 changes: 3 additions & 8 deletions redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2013,14 +2013,9 @@ class RedisImpl implements Redis {
member: string,
opts?: ZAddOpts,
) {
const args: (string | number)[] = [key, score, member];
if (opts?.mode) {
args.push(opts.mode);
}
if (opts?.ch) {
args.push("CH");
}
args.push("INCR");
const args: (string | number)[] = [key];
this.pushZAddOpts(args, opts);
args.push("INCR", score, member);
return this.execBulkReply("ZADD", ...args);
}

Expand Down
28 changes: 28 additions & 0 deletions tests/commands/sorted_set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,34 @@ export async function zsetTests(
);
});

await run("zaddIncr", async () => {
await client.zadd("key", 1, "a");
await client.zaddIncr("key", 2, "a");
assertEquals(await client.zscore("key", "a"), "3");
});

await run("zaddIncrWithMode", async () => {
assertEquals(
await client.zaddIncr("key", 1, "one", { mode: "XX" }),
undefined,
"no member should be added",
);
assertEquals(
await client.zaddIncr("key", 2, "two", { mode: "NX" }),
"2",
);
});

await run("zaddIncrWithCH", async () => {
await client.zadd("key", 1, "foo");
assertEquals(
await client.zaddIncr("key", 3, "foo", { ch: true }),
"4",
"`ZADD` with `INCR` should return the new score of member",
);
assertEquals(await client.zscore("key", "foo"), "4");
});

await run("zcount", async () => {
await client.zadd("key", { "1": 1, "2": 2 });
assertEquals(await client.zcount("key", 0, 1), 1);
Expand Down

0 comments on commit b2f4287

Please sign in to comment.