From 1acd4aefdfc806592815f628135d99904c7377bb Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 30 May 2024 19:29:25 +0000 Subject: [PATCH 1/7] adds HKEYS command Signed-off-by: Adar Ovadia --- node/src/BaseClient.ts | 19 +++++++++++++++++++ node/src/Commands.ts | 7 +++++++ node/src/Transaction.ts | 12 ++++++++++++ node/tests/SharedTests.ts | 35 +++++++++++++++++++++++++++++++++++ node/tests/TestUtilities.ts | 2 ++ 5 files changed, 75 insertions(+) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 3ba5739d21..ebf6cfef73 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -39,6 +39,7 @@ import { createHGetAll, createHIncrBy, createHIncrByFloat, + createHKeys, createHLen, createHMGet, createHSet, @@ -722,6 +723,24 @@ export class BaseClient { return this.createWritePromise(createHSet(key, fieldValueMap)); } + /** + * Returns all field names in the hash stored at `key`. + * See https://redis.io/commands/hkeys/ for more details. + * + * @param key - The key of the hash. + * @returns A list of field names for the hash, or an empty list when the key does not exist. + * + * @example + * ```typescript + * // Example usage of the hkeys method + * const result = await client.hkeys("my_hash") + * console.log(result); // Output: ["field1", "field2", "field3"] - Returns all the field names stored in the hash "my_hash". + * ``` + */ + public hkeys(key: string): Promise { + return this.createWritePromise(createHKeys(key)); + } + /** Sets `field` in the hash stored at `key` to `value`, only if `field` does not yet exist. * If `key` does not exist, a new key holding a hash is created. * If `field` already exists, this operation has no effect. diff --git a/node/src/Commands.ts b/node/src/Commands.ts index 12d3667589..25ffa5f8df 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -406,6 +406,13 @@ export function createHSet( ); } +/** + * @internal + */ +export function createHKeys(key: string): redis_request.Command { + return createCommand(RequestType.HKeys, [key]); +} + /** * @internal */ diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index b535eb870c..688596d956 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -40,6 +40,7 @@ import { createHGetAll, createHIncrBy, createHIncrByFloat, + createHKeys, createHLen, createHMGet, createHSet, @@ -390,6 +391,17 @@ export class BaseTransaction> { return this.addAndReturn(createHSet(key, fieldValueMap)); } + /** + * Returns all field names in the hash stored at `key`. + * See https://redis.io/commands/hkeys/ for more details. + * + * @param key - The key of the hash. + * @returns A list of field names for the hash, or an empty list when the key does not exist. + */ + public hkeys(key: string): T { + return this.addAndReturn(createHKeys(key)); + } + /** Sets `field` in the hash stored at `key` to `value`, only if `field` does not yet exist. * If `key` does not exist, a new key holding a hash is created. * If `field` already exists, this operation has no effect. diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index a14032bfa9..feba845039 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -532,6 +532,41 @@ export function runBaseTests(config: { config.timeout, ); + it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])( + `testing hkeys with exiting, an non exising key and error request key_%p`, + async (protocol) => { + await runTest(async (client: BaseClient) => { + const key = uuidv4(); + const key2 = uuidv4(); + const field1 = uuidv4(); + const field2 = uuidv4(); + const value = uuidv4(); + const value2 = uuidv4(); + const fieldValueMap = { + [field1]: value, + [field2]: value2, + }; + + expect(await client.hset(key, fieldValueMap)).toEqual(2); + expect(await client.hkeys(key)).toEqual([field1, field2]); + expect(await client.hdel(key, [field1])).toEqual(1); + expect(await client.hkeys(key)).toEqual([field2]); + expect(await client.hkeys("nonExistingKey")).toEqual([]); + + expect(await client.set(key2, value)).toEqual("OK"); + + try { + expect(await client.hkeys(key2)).toThrow(); + } catch (e) { + expect((e as Error).message).toMatch( + "WRONGTYPE: Operation against a key holding the wrong kind of value", + ); + } + }, protocol); + }, + config.timeout, + ); + it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])( `hdel multiple existing fields, an non existing field and an non existing key_%p`, async (protocol) => { diff --git a/node/tests/TestUtilities.ts b/node/tests/TestUtilities.ts index 5a78091df0..ca8dfe1363 100644 --- a/node/tests/TestUtilities.ts +++ b/node/tests/TestUtilities.ts @@ -340,6 +340,8 @@ export async function transactionTest( args.push(false); baseTransaction.hvals(key4); args.push([value]); + baseTransaction.hkeys(key4); + args.push([field]); baseTransaction.hget(key4, field); args.push(value); baseTransaction.hgetall(key4); From ecdf0335a568be5beabc7303d9104dfd62eb0aff Mon Sep 17 00:00:00 2001 From: adarovadya Date: Sun, 2 Jun 2024 11:17:59 +0300 Subject: [PATCH 2/7] Apply suggestions from code review Co-authored-by: Yury-Fridlyand Signed-off-by: Adar Ovadia --- node/src/BaseClient.ts | 2 +- node/src/Transaction.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index ebf6cfef73..5e516d2271 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -733,7 +733,7 @@ export class BaseClient { * @example * ```typescript * // Example usage of the hkeys method - * const result = await client.hkeys("my_hash") + * const result = await client.hkeys("my_hash"); * console.log(result); // Output: ["field1", "field2", "field3"] - Returns all the field names stored in the hash "my_hash". * ``` */ diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index 688596d956..a6613620b2 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -396,7 +396,8 @@ export class BaseTransaction> { * See https://redis.io/commands/hkeys/ for more details. * * @param key - The key of the hash. - * @returns A list of field names for the hash, or an empty list when the key does not exist. + * + * Command Response - A list of field names for the hash, or an empty list when the key does not exist. */ public hkeys(key: string): T { return this.addAndReturn(createHKeys(key)); From fce30e6a30a16ccc340d40d5410bef2c88b86f99 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 2 Jun 2024 08:23:28 +0000 Subject: [PATCH 3/7] change error msg check Signed-off-by: Adar Ovadia --- node/tests/SharedTests.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index feba845039..64d6f7153f 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -555,13 +555,7 @@ export function runBaseTests(config: { expect(await client.set(key2, value)).toEqual("OK"); - try { - expect(await client.hkeys(key2)).toThrow(); - } catch (e) { - expect((e as Error).message).toMatch( - "WRONGTYPE: Operation against a key holding the wrong kind of value", - ); - } + expect(await client.hkeys(key2)).rejects.toThrow(); }, protocol); }, config.timeout, From b2b224c92ed99db0fb0eebec0661a42d5fdfdba5 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 2 Jun 2024 12:50:03 +0000 Subject: [PATCH 4/7] add cmd to changelog file and ignore formatter Signed-off-by: Adar Ovadia --- CHANGELOG.md | 2 ++ node/tests/SharedTests.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 563251e54d..6be14e8486 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ #### Changes +* Node: Added HKEYS command ([#1499](https://github.com/aws/glide-for-redis/pull/1499)) +* Node: Added SMOVE command ([#1476](https://github.com/aws/glide-for-redis/pull/1476)) * Node: Added ZINTERSTORE command ([#1513](https://github.com/valkey-io/valkey-glide/pull/1513)) * Python: Added OBJECT ENCODING command ([#1471](https://github.com/valkey-io/valkey-glide/pull/1471)) * Python: Added OBJECT FREQ command ([#1472](https://github.com/valkey-io/valkey-glide/pull/1472)) diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 64d6f7153f..fdcbc87491 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -555,7 +555,7 @@ export function runBaseTests(config: { expect(await client.set(key2, value)).toEqual("OK"); - expect(await client.hkeys(key2)).rejects.toThrow(); + await expect(client.hkeys(key2)).rejects.toThrow(); }, protocol); }, config.timeout, From 6cad989128634091866b0cedaa26e9206a87b2f7 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 5 Jun 2024 14:47:19 +0000 Subject: [PATCH 5/7] remove unrelated changes Signed-off-by: Adar Ovadia --- node/.prettierignore | 1 - 1 file changed, 1 deletion(-) diff --git a/node/.prettierignore b/node/.prettierignore index 6ced842400..086fea31e1 100644 --- a/node/.prettierignore +++ b/node/.prettierignore @@ -1,6 +1,5 @@ # ignore that dir, because there are a lot of files which we don't manage, e.g. json files in cargo crates rust-client/* -*.md # unignore specific files !rust-client/package.json !rust-client/tsconfig.json From fff8e3662a41f5cc9089f25a9b5dbee62ceea8aa Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sat, 15 Jun 2024 09:41:52 +0000 Subject: [PATCH 6/7] change links to valkey Signed-off-by: Adar Ovadia --- node/src/BaseClient.ts | 2 +- node/src/Transaction.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 5e516d2271..3e8b7a08cd 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -725,7 +725,7 @@ export class BaseClient { /** * Returns all field names in the hash stored at `key`. - * See https://redis.io/commands/hkeys/ for more details. + * See https://valkey.io/commands/hkeys/ for more details. * * @param key - The key of the hash. * @returns A list of field names for the hash, or an empty list when the key does not exist. diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index a6613620b2..2aeb04f214 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -393,7 +393,7 @@ export class BaseTransaction> { /** * Returns all field names in the hash stored at `key`. - * See https://redis.io/commands/hkeys/ for more details. + * See https://valkey.io/commands/hkeys/ for more details. * * @param key - The key of the hash. * From 9f8b5019e4ba6e0d3b86eba5c28a86f94ce745c3 Mon Sep 17 00:00:00 2001 From: Adar Ovadia Date: Thu, 11 Jul 2024 12:15:43 +0000 Subject: [PATCH 7/7] change format Signed-off-by: Adar Ovadia --- node/src/Commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/Commands.ts b/node/src/Commands.ts index 25ffa5f8df..4c5b682fb5 100644 --- a/node/src/Commands.ts +++ b/node/src/Commands.ts @@ -409,7 +409,7 @@ export function createHSet( /** * @internal */ -export function createHKeys(key: string): redis_request.Command { +export function createHKeys(key: string): command_request.Command { return createCommand(RequestType.HKeys, [key]); }