Skip to content

Commit

Permalink
Node: added hvals command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adan committed Feb 22, 2024
1 parent 44ef9a9 commit f24b56d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions glide-core/src/protobuf/redis_request.proto
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ enum RequestType {
XTrim = 79;
XGroupCreate = 80;
XGroupDestroy = 81;
Hvals = 82;
}

message Command {
Expand Down
1 change: 1 addition & 0 deletions glide-core/src/socket_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ fn get_command(request: &Command) -> Option<Cmd> {
RequestType::XGroupCreate => Some(get_two_word_command("XGROUP", "CREATE")),
RequestType::XGroupDestroy => Some(get_two_word_command("XGROUP", "DESTROY")),
RequestType::XTrim => Some(cmd("XTRIM")),
RequestType::Hvals => Some(cmd("HVALS")),
}
}

Expand Down
11 changes: 11 additions & 0 deletions node/src/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
createHLen,
createHMGet,
createHSet,
createHvals,
createIncr,
createIncrBy,
createIncrByFloat,
Expand Down Expand Up @@ -631,6 +632,16 @@ export class BaseClient {
return this.createWritePromise(createHLen(key));
}

/** Returns all values in the hash stored at key.
* See https://redis.io/commands/hvals/ for more details.
*
* @param key - The key of the hash.
* @returns a list of values in the hash, or an empty list when the key does not exist
*/
public hvals(key: string): Promise<string[]> {
return this.createWritePromise(createHvals(key));
}

/** Inserts all the specified values at the head of the list stored at `key`.
* `elements` are inserted one after the other to the head of the list, from the leftmost element to the rightmost element.
* If `key` does not exist, it is created as empty list before performing the push operations.
Expand Down
7 changes: 7 additions & 0 deletions node/src/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,13 @@ export function createHLen(key: string): redis_request.Command {
return createCommand(RequestType.HLen, [key]);
}

/**
* @internal
*/
export function createHvals(key: string): redis_request.Command {
return createCommand(RequestType.Hvals, [key]);
}

/**
* @internal
*/
Expand Down
12 changes: 12 additions & 0 deletions node/src/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
createHLen,
createHMGet,
createHSet,
createHvals,
createIncr,
createIncrBy,
createIncrByFloat,
Expand Down Expand Up @@ -425,6 +426,17 @@ export class BaseTransaction<T extends BaseTransaction<T>> {
return this.addAndReturn(createHLen(key));
}

/** Returns all values in the hash stored at key.
* See https://redis.io/commands/hvals/ for more details.
*
* @param key - The key of the hash.
*
* Command Response - a list of values in the hash, or an empty list when the key does not exist
*/
public hvals(key: string): T {
return this.addAndReturn(createHvals(key));
}

/** Inserts all the specified values at the head of the list stored at `key`.
* `elements` are inserted one after the other to the head of the list, from the leftmost element to the rightmost element.
* If `key` does not exist, it is created as empty list before performing the push operations.
Expand Down
22 changes: 22 additions & 0 deletions node/tests/SharedTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,28 @@ export function runBaseTests<Context>(config: {
config.timeout
);

it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
`hvals test_%p`,
async (protocol) => {
await runTest(async (client: BaseClient) => {
const key1 = uuidv4();
const field1 = uuidv4();
const field2 = uuidv4();
const fieldValueMap = {
[field1]: "value1",
[field2]: "value2",
};

expect(await client.hset(key1, fieldValueMap)).toEqual(2);
expect(await client.hvals(key1)).toEqual(["value1", "value2"]);
expect(await client.hdel(key1, [field1])).toEqual(1);
expect(await client.hvals(key1)).toEqual(["value2"]);
expect(await client.hvals("nonExistingHash")).toEqual([]);
}, protocol);
},
config.timeout
);

it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
`lpush, lpop and lrange with existing and non existing key_%p`,
async (protocol) => {
Expand Down
2 changes: 2 additions & 0 deletions node/tests/TestUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export function transactionTest(
args.push(1);
baseTransaction.hlen(key4);
args.push(1);
baseTransaction.hvals(key4);
args.push([value]);
baseTransaction.hget(key4, field);
args.push(value);
baseTransaction.hgetall(key4);
Expand Down

0 comments on commit f24b56d

Please sign in to comment.