Skip to content

Commit e7347f8

Browse files
authored
DOC-3914: re-issue TCE PRs previously issued by justincastilla (#2781)
1 parent 70f3606 commit e7347f8

8 files changed

+1154
-146
lines changed

doctests/dt-bitmap.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// EXAMPLE: bitmap_tutorial
2+
// HIDE_START
3+
import assert from 'assert';
4+
import { createClient } from 'redis';
5+
6+
const client = createClient();
7+
await client.connect();
8+
// HIDE_END
9+
10+
// REMOVE_START
11+
await client.flushDb();
12+
// REMOVE_END
13+
14+
// STEP_START ping
15+
const res1 = await client.setBit("pings:2024-01-01-00:00", 123, 1)
16+
console.log(res1) // >>> 0
17+
18+
const res2 = await client.getBit("pings:2024-01-01-00:00", 123)
19+
console.log(res2) // >>> 1
20+
21+
const res3 = await client.getBit("pings:2024-01-01-00:00", 456)
22+
console.log(res3) // >>> 0
23+
// STEP_END
24+
25+
// REMOVE_START
26+
assert.equal(res1, 0)
27+
// REMOVE_END
28+
29+
// STEP_START bitcount
30+
// HIDE_START
31+
await client.setBit("pings:2024-01-01-00:00", 123, 1)
32+
// HIDE_END
33+
const res4 = await client.bitCount("pings:2024-01-01-00:00")
34+
console.log(res4) // >>> 1
35+
// STEP_END
36+
// REMOVE_START
37+
assert.equal(res4, 1)
38+
await client.quit();
39+
// REMOVE_END

doctests/dt-hash.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// EXAMPLE: hash_tutorial
2+
// HIDE_START
3+
import assert from 'assert';
4+
import { createClient } from 'redis';
5+
6+
const client = createClient();
7+
await client.connect();
8+
// HIDE_END
9+
// STEP_START set_get_all
10+
const res1 = await client.hSet(
11+
'bike:1',
12+
{
13+
'model': 'Deimos',
14+
'brand': 'Ergonom',
15+
'type': 'Enduro bikes',
16+
'price': 4972,
17+
}
18+
)
19+
console.log(res1) // 4
20+
21+
const res2 = await client.hGet('bike:1', 'model')
22+
console.log(res2) // 'Deimos'
23+
24+
const res3 = await client.hGet('bike:1', 'price')
25+
console.log(res3) // '4972'
26+
27+
const res4 = await client.hGetAll('bike:1')
28+
console.log(res4)
29+
/*
30+
{
31+
brand: 'Ergonom',
32+
model: 'Deimos',
33+
price: '4972',
34+
type: 'Enduro bikes'
35+
}
36+
*/
37+
// STEP_END
38+
39+
// REMOVE_START
40+
assert.equal(res1, 4);
41+
assert.equal(res2, 'Deimos');
42+
assert.equal(res3, '4972');
43+
assert.deepEqual(res4, {
44+
model: 'Deimos',
45+
brand: 'Ergonom',
46+
type: 'Enduro bikes',
47+
price: '4972'
48+
});
49+
// REMOVE_END
50+
51+
// STEP_START hmGet
52+
const res5 = await client.hmGet('bike:1', ['model', 'price'])
53+
console.log(res5) // ['Deimos', '4972']
54+
// STEP_END
55+
56+
// REMOVE_START
57+
assert.deepEqual(Object.values(res5), ['Deimos', '4972'])
58+
// REMOVE_END
59+
60+
// STEP_START hIncrBy
61+
const res6 = await client.hIncrBy('bike:1', 'price', 100)
62+
console.log(res6) // 5072
63+
const res7 = await client.hIncrBy('bike:1', 'price', -100)
64+
console.log(res7) // 4972
65+
// STEP_END
66+
67+
// REMOVE_START
68+
assert.equal(res6, 5072)
69+
assert.equal(res7, 4972)
70+
// REMOVE_END
71+
72+
// STEP_START hIncrBy_hGet_hMget
73+
const res11 = await client.hIncrBy('bike:1:stats', 'rides', 1)
74+
console.log(res11) // 1
75+
const res12 = await client.hIncrBy('bike:1:stats', 'rides', 1)
76+
console.log(res12) // 2
77+
const res13 = await client.hIncrBy('bike:1:stats', 'rides', 1)
78+
console.log(res13) // 3
79+
const res14 = await client.hIncrBy('bike:1:stats', 'crashes', 1)
80+
console.log(res14) // 1
81+
const res15 = await client.hIncrBy('bike:1:stats', 'owners', 1)
82+
console.log(res15) // 1
83+
const res16 = await client.hGet('bike:1:stats', 'rides')
84+
console.log(res16) // 3
85+
const res17 = await client.hmGet('bike:1:stats', ['crashes', 'owners'])
86+
console.log(res17) // ['1', '1']
87+
// STEP_END
88+
89+
// REMOVE_START
90+
assert.equal(res11, 1);
91+
assert.equal(res12, 2);
92+
assert.equal(res13, 3);
93+
assert.equal(res14, 1);
94+
assert.equal(res15, 1);
95+
assert.equal(res16, '3');
96+
assert.deepEqual(res17, ['1', '1']);
97+
await client.quit();
98+
// REMOVE_END

0 commit comments

Comments
 (0)