diff --git a/pkg/commands/zremrangebyscore.test.ts b/pkg/commands/zremrangebyscore.test.ts index b4beacb2..fa6b68c1 100644 --- a/pkg/commands/zremrangebyscore.test.ts +++ b/pkg/commands/zremrangebyscore.test.ts @@ -1,15 +1,17 @@ import { keygen, newHttpClient, randomID } from "../test-utils"; -import { afterAll, expect, test } from "bun:test"; +import { afterEach, beforeEach, expect, test } from "bun:test"; import { ZAddCommand } from "./zadd"; import { ZRemRangeByScoreCommand } from "./zremrangebyscore"; const client = newHttpClient(); const { newKey, cleanup } = keygen(); -afterAll(cleanup); -test("returns the number of removed elements", async () => { - const key = newKey(); + +const key = newKey(); + +afterEach(cleanup); +beforeEach(async () => { const member1 = randomID(); const member2 = randomID(); const member3 = randomID(); @@ -19,6 +21,19 @@ test("returns the number of removed elements", async () => { { score: 2, member: member2 }, { score: 3, member: member3 }, ]).exec(client); +}); + +test("returns the number of removed elements", async () => { const res = await new ZRemRangeByScoreCommand([key, 1, 2]).exec(client); expect(res).toEqual(2); }); + +test("returns the number of removed elements with inf", async () => { + const res = await new ZRemRangeByScoreCommand([key, "-inf", "+inf"]).exec(client); + expect(res).toEqual(3); +}); + +test("returns the number of removed elements with exclusive range", async () => { + const res = await new ZRemRangeByScoreCommand([key, "(1", "(3"]).exec(client); + expect(res).toEqual(1); +}); diff --git a/pkg/commands/zremrangebyscore.ts b/pkg/commands/zremrangebyscore.ts index b16e083d..a6127d5a 100644 --- a/pkg/commands/zremrangebyscore.ts +++ b/pkg/commands/zremrangebyscore.ts @@ -4,7 +4,14 @@ import { Command } from "./command"; * @see https://redis.io/commands/zremrangebyscore */ export class ZRemRangeByScoreCommand extends Command { - constructor(cmd: [key: string, min: number, max: number], opts?: CommandOptions) { + constructor( + cmd: [ + key: string, + min: number | `(${number}` | "-inf" | "+inf", + max: number | `(${number}` | "-inf" | "+inf", + ], + opts?: CommandOptions + ) { super(["zremrangebyscore", ...cmd], opts); } }