-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(command): return keys in HMGET command correctly
- Loading branch information
Showing
5 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |