1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

TCEs for select command pages (#2824)

* TCEs for select command pages

* Preemptive modifications from previous reviews

* Update to previous commit
This commit is contained in:
David Dougherty
2024-09-26 04:27:12 -07:00
committed by GitHub
parent ebd2037e48
commit fd7b10be6c
4 changed files with 408 additions and 0 deletions

71
doctests/cmds-hash.js Normal file
View File

@@ -0,0 +1,71 @@
// EXAMPLE: cmds_hash
// HIDE_START
import assert from 'node:assert';
import { createClient } from 'redis';
const client = createClient();
await client.connect().catch(console.error);
// HIDE_END
// STEP_START hset
const res1 = await client.hSet('myhash', 'field1', 'Hello')
console.log(res1) // 1
const res2 = await client.hGet('myhash', 'field1')
console.log(res2) // Hello
const res3 = await client.hSet(
'myhash',
{
'field2': 'Hi',
'field3': 'World'
}
)
console.log(res3) // 2
const res4 = await client.hGet('myhash', 'field2')
console.log(res4) // Hi
const res5 = await client.hGet('myhash', 'field3')
console.log(res5) // World
const res6 = await client.hGetAll('myhash')
console.log(res6)
// REMOVE_START
assert.equal(res1, 1);
assert.equal(res2, 'Hello');
assert.equal(res3, 2);
assert.equal(res4, 'Hi');
assert.equal(res5, 'World');
assert.deepEqual(res6, {
field1: 'Hello',
field2: 'Hi',
field3: 'World'
});
await client.del('myhash')
// REMOVE_END
// STEP_END
// STEP_START hget
const res7 = await client.hSet('myhash', 'field1', 'foo')
console.log(res7) // 1
const res8 = await client.hGet('myhash', 'field1')
console.log(res8) // foo
const res9 = await client.hGet('myhash', 'field2')
console.log(res9) // foo
// REMOVE_START
assert.equal(res7, 1);
assert.equal(res8, 'foo');
assert.equal(res9, null);
await client.del('myhash')
// REMOVE_END
// STEP_END
// HIDE_START
await client.quit();
// HIDE_END