diff --git a/pkg/commands/mget.ts b/pkg/commands/mget.ts index 2380751a..ba716210 100644 --- a/pkg/commands/mget.ts +++ b/pkg/commands/mget.ts @@ -2,14 +2,15 @@ import { Command, CommandOptions } from "./command.ts"; /** * @see https://redis.io/commands/mget */ -export class MGetCommand extends Command< - (string | null)[], - TData -> { +export class MGetCommand + extends Command<(string | null)[], TData> { constructor( - cmd: [...keys: string[]], + cmd: [string[]] | [...string[] | string[]], opts?: CommandOptions<(string | null)[], TData>, ) { - super(["mget", ...cmd], opts); + const keys = Array.isArray(cmd[0]) + ? (cmd[0] as string[]) + : (cmd as string[]); + super(["mget", ...keys], opts); } } diff --git a/pkg/redis.test.ts b/pkg/redis.test.ts index c50ef649..9497c969 100644 --- a/pkg/redis.test.ts +++ b/pkg/redis.test.ts @@ -37,6 +37,29 @@ Deno.test("when storing base64 data", async (t) => { }); }); +Deno.test("mget", async (t) => { + const key = newKey(); + const key1 = newKey(); + const value = "foobar"; + const value1 = "foobar1"; + const redis = new Redis(client); + const queries = [key, key1]; + + await t.step("mget with array", async () => { + await redis.mset({ key: value, key1: value1 }); + const res = await redis.mget(queries); + + assertEquals(res.length, 2); + }); + + await t.step("mget with spreaded array", async () => { + await redis.mset({ key: value, key1: value1 }); + const res = await redis.mget(...queries); + + assertEquals(res.length, 2); + }); +}); + Deno.test("when destructuring the redis class", async (t) => { await t.step("correctly binds this", async () => { const { get, set } = new Redis(client); diff --git a/pkg/redis.ts b/pkg/redis.ts index 0d5d1fb4..03d17bcc 100644 --- a/pkg/redis.ts +++ b/pkg/redis.ts @@ -416,7 +416,9 @@ export class Redis { new BitOpCommand( [op as any, destinationKey, sourceKey, ...sourceKeys], this.opts, - ).exec(this.client); + ).exec( + this.client, + ); /** * @see https://redis.io/commands/bitpos @@ -604,10 +606,8 @@ export class Redis { count?: number, withValues?: boolean, ) => - new HRandFieldCommand( - [key, count, withValues] as any, - this.opts, - ).exec(this.client); + new HRandFieldCommand([key, count, withValues] as any, this.opts) + .exec(this.client); /** * @see https://redis.io/commands/hscan