Skip to content

Commit 06ec545

Browse files
committed
fix(command): return keys in HMGET command correctly
1 parent 192744e commit 06ec545

File tree

5 files changed

+83
-5
lines changed

5 files changed

+83
-5
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes Logs
22

3+
## v3.0.3
4+
5+
- fix(command): Return keys in `HMGET` command correctly.
6+
37
## v3.0.2
48

59
- fix(command): Incorrect preprocessing of arguments for `SREM` command.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@litert/redis",
3-
"version": "3.0.2",
3+
"version": "3.0.3",
44
"description": "A redis protocol implement for Node.js.",
55
"main": "./lib/index.js",
66
"scripts": {

src/lib/Commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
11321132
},
11331133
process(data: Array<[number, Buffer]>, args: any[]): any {
11341134

1135-
return U.list2NullableStringDict(args[1], data);
1135+
return U.list2NullableStringDict(args.slice(1), data);
11361136
}
11371137
},
11381138

@@ -1163,7 +1163,7 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
11631163
},
11641164
process(data: Array<[number, Buffer]>, args: any[]): any {
11651165

1166-
return U.list2NullableBufferDict(args[1], data);
1166+
return U.list2NullableBufferDict(args.slice(1), data);
11671167
}
11681168
},
11691169

src/test/commands/hash.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { test } from 'node:test';
2+
import * as Assert from 'node:assert';
3+
import { cmdCli } from '../common';
4+
5+
const TEST_KEY_PREFIX = 'test_hash_';
6+
7+
test('Command For Hashes', async (t) => {
8+
9+
await cmdCli.del([...await cmdCli.keys(`${TEST_KEY_PREFIX}*`), 'any']);
10+
11+
await t.test('Create a hash with one key', async () => {
12+
13+
Assert.strictEqual(await cmdCli.hSet(`${TEST_KEY_PREFIX}a`, 'key1', 'a'), true);
14+
Assert.strictEqual(await cmdCli.hSet(`${TEST_KEY_PREFIX}b`, 'key1', 'b'), true);
15+
16+
Assert.ok(true);
17+
});
18+
19+
await t.test('Get value of one key in a hash', async () => {
20+
21+
Assert.strictEqual(await cmdCli.hGet(`${TEST_KEY_PREFIX}a`, 'key1'), 'a');
22+
Assert.strictEqual(await cmdCli.hGet(`${TEST_KEY_PREFIX}b`, 'key1'), 'b');
23+
});
24+
25+
await t.test('Create a hash with multiple keys', async () => {
26+
27+
await cmdCli.hMSet(`${TEST_KEY_PREFIX}m1`, {
28+
'k1': 'x',
29+
'k2': 'y',
30+
'k3': 'z'
31+
});
32+
33+
Assert.ok(true);
34+
});
35+
36+
await t.test('Get values of multiple keys in a hash', async () => {
37+
38+
Assert.deepStrictEqual(await cmdCli.hMGet(`${TEST_KEY_PREFIX}m1`, ['k1', 'k2']), {
39+
'k1': 'x',
40+
'k2': 'y',
41+
});
42+
43+
Assert.deepStrictEqual(await cmdCli.hMGet$(`${TEST_KEY_PREFIX}m1`, ['k1', 'k2']), {
44+
'k1': Buffer.from('x'),
45+
'k2': Buffer.from('y'),
46+
});
47+
48+
Assert.deepStrictEqual(await cmdCli.hMGet(`${TEST_KEY_PREFIX}m1`, ['k1', 'k2', 'k4']), {
49+
'k1': 'x',
50+
'k2': 'y',
51+
'k4': null,
52+
});
53+
54+
Assert.deepStrictEqual(await cmdCli.hMGet$(`${TEST_KEY_PREFIX}m1`, ['k1', 'k2', 'k4']), {
55+
'k1': Buffer.from('x'),
56+
'k2': Buffer.from('y'),
57+
'k4': null,
58+
});
59+
});
60+
61+
await t.test('Get values of all keys in a hash', async () => {
62+
63+
Assert.deepStrictEqual(await cmdCli.hGetAll(`${TEST_KEY_PREFIX}m1`), {
64+
'k1': 'x',
65+
'k2': 'y',
66+
'k3': 'z',
67+
});
68+
});
69+
});
70+
71+
test.after(async () => {
72+
73+
await cmdCli.close();
74+
});

0 commit comments

Comments
 (0)