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
48 changes: 48 additions & 0 deletions pkg/commands/getdel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { keygen, newHttpClient, randomID } from "../test-utils.ts";

import { afterAll } from "https://deno.land/[email protected]/testing/bdd.ts";
import { SetCommand } from "./set.ts";
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { GetDelCommand } from "./getdel.ts";
import { GetCommand } from "./get.ts";
const client = newHttpClient();

const { newKey, cleanup } = keygen();
afterAll(cleanup);

Deno.test(
"gets an exiting value, then deletes",
async () => {
const key = newKey();
const value = randomID();
await new SetCommand([key, value]).exec(client);
const res = await new GetDelCommand([key]).exec(client);

assertEquals(res, value);

const res2 = await new GetCommand([key]).exec(client);
assertEquals(res2, null);
},
);

Deno.test(
"gets a non-existing value",
async () => {
const key = newKey();
const res = await new GetDelCommand([key]).exec(client);

assertEquals(res, null);
},
);

Deno.test(
"gets an object",
async () => {
const key = newKey();
const value = { v: randomID() };
await new SetCommand([key, value]).exec(client);
const res = await new GetDelCommand<{ v: string }>([key]).exec(client);

assertEquals(res, value);
},
);
16 changes: 16 additions & 0 deletions pkg/commands/getdel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Command, CommandOptions } from "./command.ts";

/**
* @see https://redis.io/commands/getdel
*/
export class GetDelCommand<TData = string> extends Command<
unknown | null,
TData | null
> {
constructor(
cmd: [key: string],
opts?: CommandOptions<unknown | null, TData | null>,
) {
super(["getdel", ...cmd], opts);
}
}
1 change: 1 addition & 0 deletions pkg/commands/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export * from "./get.ts";
export * from "./getbit.ts";
export * from "./getrange.ts";
export * from "./getset.ts";
export * from "./getdel.ts";
export * from "./hdel.ts";
export * from "./hexists.ts";
export * from "./hget.ts";
Expand Down
1 change: 0 additions & 1 deletion pkg/commands/scan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Deno.test("without options", async (t) => {
const found: string[] = [];
do {
const res = await new ScanCommand([cursor]).exec(client);
assertEquals(typeof res[0], "number");
cursor = res[0];
found.push(...res[1]);
} while (cursor != 0);
Expand Down
3 changes: 2 additions & 1 deletion pkg/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Deno.test("use all the things", async (t) => {
.flushdb()
.get(newKey())
.getbit(newKey(), 0)
.getdel(newKey())
.getrange(newKey(), 0, 1)
.getset(newKey(), "hello")
.hdel(newKey(), "field")
Expand Down Expand Up @@ -214,6 +215,6 @@ Deno.test("use all the things", async (t) => {
.zunionstore(newKey(), 1, [newKey()]);

const res = await p.exec();
assertEquals(res.length, 114);
assertEquals(res.length, 115);
});
});
7 changes: 6 additions & 1 deletion pkg/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
FlushDBCommand,
GetBitCommand,
GetCommand,
GetDelCommand,
GetRangeCommand,
GetSetCommand,
HDelCommand,
Expand Down Expand Up @@ -351,7 +352,11 @@ export class Pipeline {
*/
getbit = (...args: CommandArgs<typeof GetBitCommand>) =>
this.chain(new GetBitCommand(args, this.commandOptions));

/**
* @see https://redis.io/commands/getdel
*/
getdel = <TData>(...args: CommandArgs<typeof GetDelCommand>) =>
this.chain(new GetDelCommand<TData>(args, this.commandOptions));
/**
* @see https://redis.io/commands/getrange
*/
Expand Down
6 changes: 6 additions & 0 deletions pkg/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
FlushDBCommand,
GetBitCommand,
GetCommand,
GetDelCommand,
GetRangeCommand,
GetSetCommand,
HDelCommand,
Expand Down Expand Up @@ -329,6 +330,11 @@ export class Redis {
*/
getbit = (...args: CommandArgs<typeof GetBitCommand>) =>
new GetBitCommand(args, this.opts).exec(this.client);
/**
* @see https://redis.io/commands/getdel
*/
getdel = <TData>(...args: CommandArgs<typeof GetDelCommand>) =>
new GetDelCommand<TData>(args, this.opts).exec(this.client);

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