Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
13 changes: 7 additions & 6 deletions pkg/commands/mget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { Command, CommandOptions } from "./command.ts";
/**
* @see https://redis.io/commands/mget
*/
export class MGetCommand<TData extends unknown[]> extends Command<
(string | null)[],
TData
> {
export class MGetCommand<TData extends unknown[]>
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);
}
}
23 changes: 23 additions & 0 deletions pkg/redis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions pkg/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -604,10 +606,8 @@ export class Redis {
count?: number,
withValues?: boolean,
) =>
new HRandFieldCommand<TData>(
[key, count, withValues] as any,
this.opts,
).exec(this.client);
new HRandFieldCommand<TData>([key, count, withValues] as any, this.opts)
.exec(this.client);

/**
* @see https://redis.io/commands/hscan
Expand Down