Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node: implement GETDEL #1968

Merged
merged 28 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6d032ed
Java Update README (#1944)
Yury-Fridlyand Jul 16, 2024
0a9ef94
current progress
cyip10 Jul 17, 2024
7c1833f
implement getdel
cyip10 Jul 17, 2024
0d6f064
implement getdel
cyip10 Jul 17, 2024
768fa63
update changelog
cyip10 Jul 17, 2024
67f685c
removed json file
cyip10 Jul 18, 2024
69c8265
implement lset
cyip10 Jul 16, 2024
b8a37d4
add changelog and edited tests
cyip10 Jul 16, 2024
cb1c63f
Updated attribution files
Jul 17, 2024
9aa12af
Fixes for java client release pipeline (#1922)
Yury-Fridlyand Jul 17, 2024
985d950
write rpushx shared test
cyip10 Jul 17, 2024
454d67c
add rpushx test
cyip10 Jul 17, 2024
ddd9b9a
implement both shared command tests
cyip10 Jul 17, 2024
14f9259
implement rpushx and lpushx
cyip10 Jul 17, 2024
8626a21
updated changelog
cyip10 Jul 17, 2024
6181c98
address comments
cyip10 Jul 17, 2024
8e7d9eb
addressed remaining comment
cyip10 Jul 17, 2024
ed8aa27
Node: add SINTERCARD command (#1956)
aaron-congo Jul 17, 2024
347b743
Node: Add LOLWUT command (#1934)
yipin-chen Jul 17, 2024
4acccda
Node: add SMISMEMBER command (#1955)
aaron-congo Jul 17, 2024
18eb4ad
Node: Add command FLUSHALL (#1958)
tjzhang-BQ Jul 17, 2024
10a2c93
Node: add `LPOS` command (#1927)
GumpacG Jul 18, 2024
af9f26f
Node: Add command DBSize (#1932)
tjzhang-BQ Jul 18, 2024
4a48337
Node: add PubSub support (#1964)
shohamazon Jul 18, 2024
fae3526
remove dash
cyip10 Jul 18, 2024
9fa71a5
Merge branch 'main' into node/integ_cyip10_getdel
cyip10 Jul 18, 2024
0138583
ran linters and fixed changelog
cyip10 Jul 18, 2024
8b9a889
Merge branch 'node/integ_cyip10_getdel' of https://github.com/Bit-Qui…
cyip10 Jul 18, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#### Changes
* Node: Added GETDEL command ([#1968](https://github.com/valkey-io/valkey-glide/pull/1968))
* Node: Added LPUSHX and RPUSHX command([#1959](https://github.com/valkey-io/valkey-glide/pull/1959))
* Node: Added LSET command ([#1952](https://github.com/valkey-io/valkey-glide/pull/1952))
* Node: Added SDIFFSTORE command ([#1931](https://github.com/valkey-io/valkey-glide/pull/1931))
Expand Down
21 changes: 21 additions & 0 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
createExpire,
createExpireAt,
createGet,
createGetDel,
createHDel,
createHExists,
createHGet,
Expand Down Expand Up @@ -743,6 +744,26 @@ export class BaseClient {
return this.createWritePromise(createGet(key));
}

/**
* Gets a string value associated with the given `key`and deletes the key.
*
* See https://valkey.io/commands/getdel/ for details.
*
* @param key - The key to retrieve from the database.
* @returns If `key` exists, returns the `value` of `key`. Otherwise, return `null`.
*
* @example
* ```typescript
* const result = client.getdel("key");
* console.log(result); // Output: 'value'
*
* const value = client.getdel("key"); // value is null
cyip10 marked this conversation as resolved.
Show resolved Hide resolved
* ```
*/
public getdel(key: string): Promise<string | null> {
return this.createWritePromise(createGetDel(key));
}

/** Set the given key with the given value. Return value is dependent on the passed options.
* See https://valkey.io/commands/set/ for details.
*
Expand Down
7 changes: 7 additions & 0 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export function createGet(key: string): command_request.Command {
return createCommand(RequestType.Get, [key]);
}

/**
* @internal
*/
export function createGetDel(key: string): command_request.Command {
return createCommand(RequestType.GetDel, [key]);
}

export type SetOptions = {
/**
* `onlyIfDoesNotExist` - Only set the key if it does not already exist.
Expand Down
14 changes: 14 additions & 0 deletions node/src/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
createExpireAt,
createFlushAll,
createGet,
createGetDel,
createHDel,
createHExists,
createHGet,
Expand Down Expand Up @@ -187,6 +188,19 @@ export class BaseTransaction<T extends BaseTransaction<T>> {
return this.addAndReturn(createGet(key));
}

/**
* Gets a string value associated with the given `key`and deletes the key.
*
* See https://valkey.io/commands/getdel/ for details.
*
* @param key - The key to retrieve from the database.
*
* Command Response - If `key` exists, returns the `value` of `key`. Otherwise, return `null`.
*/
public getdel(key: string): T {
return this.addAndReturn(createGetDel(key));
}

/** Set the given key with the given value. Return value is dependent on the passed options.
* See https://valkey.io/commands/set/ for details.
*
Expand Down
20 changes: 20 additions & 0 deletions node/tests/SharedTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,26 @@ export function runBaseTests<Context>(config: {
config.timeout,
);

it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
`getdel test_%p`,
async (protocol) => {
await runTest(async (client: BaseClient) => {
const key1 = uuidv4();
const value1 = uuidv4();
const key2 = uuidv4();

expect(await client.set(key1, value1)).toEqual("OK");
checkSimple(await client.getdel(key1)).toEqual(value1);
expect(await client.getdel(key1)).toEqual(null);

// key isn't a string
expect(await client.sadd(key2, ["a"])).toEqual(1);
await expect(client.getdel(key2)).rejects.toThrow(RequestError);
}, protocol);
},
config.timeout,
);

it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
`testing hset and hget with multiple existing fields and one non existing field_%p`,
async (protocol) => {
Expand Down
4 changes: 4 additions & 0 deletions node/tests/TestUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ export async function transactionTest(
args.push(0);
baseTransaction.set(key1, "bar");
args.push("OK");
baseTransaction.getdel(key1);
args.push("bar");
baseTransaction.set(key1, "bar");
args.push("OK");
baseTransaction.objectEncoding(key1);
args.push("embstr");
baseTransaction.type(key1);
Expand Down
Loading