Skip to content

Commit

Permalink
fix(command): return keys in HMGET command correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fenying committed Jul 6, 2024
1 parent 192744e commit 06ec545
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes Logs

## v3.0.3

- fix(command): Return keys in `HMGET` command correctly.

## v3.0.2

- fix(command): Incorrect preprocessing of arguments for `SREM` command.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@litert/redis",
"version": "3.0.2",
"version": "3.0.3",
"description": "A redis protocol implement for Node.js.",
"main": "./lib/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ export const COMMANDS: Record<keyof C.ICommandAPIs, ICommand> = {
},
process(data: Array<[number, Buffer]>, args: any[]): any {

return U.list2NullableStringDict(args[1], data);
return U.list2NullableStringDict(args.slice(1), data);
}
},

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

return U.list2NullableBufferDict(args[1], data);
return U.list2NullableBufferDict(args.slice(1), data);
}
},

Expand Down
74 changes: 74 additions & 0 deletions src/test/commands/hash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { test } from 'node:test';
import * as Assert from 'node:assert';
import { cmdCli } from '../common';

const TEST_KEY_PREFIX = 'test_hash_';

test('Command For Hashes', async (t) => {

await cmdCli.del([...await cmdCli.keys(`${TEST_KEY_PREFIX}*`), 'any']);

await t.test('Create a hash with one key', async () => {

Assert.strictEqual(await cmdCli.hSet(`${TEST_KEY_PREFIX}a`, 'key1', 'a'), true);
Assert.strictEqual(await cmdCli.hSet(`${TEST_KEY_PREFIX}b`, 'key1', 'b'), true);

Assert.ok(true);
});

await t.test('Get value of one key in a hash', async () => {

Assert.strictEqual(await cmdCli.hGet(`${TEST_KEY_PREFIX}a`, 'key1'), 'a');
Assert.strictEqual(await cmdCli.hGet(`${TEST_KEY_PREFIX}b`, 'key1'), 'b');
});

await t.test('Create a hash with multiple keys', async () => {

await cmdCli.hMSet(`${TEST_KEY_PREFIX}m1`, {
'k1': 'x',
'k2': 'y',
'k3': 'z'
});

Assert.ok(true);
});

await t.test('Get values of multiple keys in a hash', async () => {

Assert.deepStrictEqual(await cmdCli.hMGet(`${TEST_KEY_PREFIX}m1`, ['k1', 'k2']), {
'k1': 'x',
'k2': 'y',
});

Assert.deepStrictEqual(await cmdCli.hMGet$(`${TEST_KEY_PREFIX}m1`, ['k1', 'k2']), {
'k1': Buffer.from('x'),
'k2': Buffer.from('y'),
});

Assert.deepStrictEqual(await cmdCli.hMGet(`${TEST_KEY_PREFIX}m1`, ['k1', 'k2', 'k4']), {
'k1': 'x',
'k2': 'y',
'k4': null,
});

Assert.deepStrictEqual(await cmdCli.hMGet$(`${TEST_KEY_PREFIX}m1`, ['k1', 'k2', 'k4']), {
'k1': Buffer.from('x'),
'k2': Buffer.from('y'),
'k4': null,
});
});

await t.test('Get values of all keys in a hash', async () => {

Assert.deepStrictEqual(await cmdCli.hGetAll(`${TEST_KEY_PREFIX}m1`), {
'k1': 'x',
'k2': 'y',
'k3': 'z',
});
});
});

test.after(async () => {

await cmdCli.close();
});

0 comments on commit 06ec545

Please sign in to comment.