Skip to content

Commit 0f3d0f3

Browse files
authored
DOC-3933: final 8 tabbed code examples (#2784)
1 parent e7347f8 commit 0f3d0f3

File tree

8 files changed

+543
-0
lines changed

8 files changed

+543
-0
lines changed

doctests/dt-bitfield.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// EXAMPLE: bitfield_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 bf
15+
let res1 = await client.bitField("bike:1:stats", [{
16+
operation: 'SET',
17+
encoding: 'u32',
18+
offset: '#0',
19+
value: 1000
20+
}]);
21+
console.log(res1); // >>> [0]
22+
23+
let res2 = await client.bitField('bike:1:stats', [
24+
{
25+
operation: 'INCRBY',
26+
encoding: 'u32',
27+
offset: '#0',
28+
increment: -50
29+
},
30+
{
31+
operation: 'INCRBY',
32+
encoding: 'u32',
33+
offset: '#1',
34+
increment: 1
35+
}
36+
]);
37+
console.log(res2); // >>> [950, 1]
38+
39+
let res3 = await client.bitField('bike:1:stats', [
40+
{
41+
operation: 'INCRBY',
42+
encoding: 'u32',
43+
offset: '#0',
44+
increment: 500
45+
},
46+
{
47+
operation: 'INCRBY',
48+
encoding: 'u32',
49+
offset: '#1',
50+
increment: 1
51+
}
52+
]);
53+
console.log(res3); // >>> [1450, 2]
54+
55+
let res4 = await client.bitField('bike:1:stats', [
56+
{
57+
operation: 'GET',
58+
encoding: 'u32',
59+
offset: '#0'
60+
},
61+
{
62+
operation: 'GET',
63+
encoding: 'u32',
64+
offset: '#1'
65+
}
66+
]);
67+
console.log(res4); // >>> [1450, 2]
68+
// STEP_END
69+
70+
// REMOVE_START
71+
assert.deepEqual(res1, [0])
72+
assert.deepEqual(res2, [950, 1])
73+
assert.deepEqual(res3, [1450, 2])
74+
assert.deepEqual(res4, [1450, 2])
75+
await client.quit();
76+
// REMOVE_END

doctests/dt-bloom.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// EXAMPLE: bf_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 bloom
15+
const res1 = await client.bf.reserve('bikes:models', 0.01, 1000);
16+
console.log(res1); // >>> OK
17+
18+
const res2 = await client.bf.add('bikes:models', 'Smoky Mountain Striker');
19+
console.log(res2); // >>> true
20+
21+
const res3 = await client.bf.exists('bikes:models', 'Smoky Mountain Striker');
22+
console.log(res3); // >>> true
23+
24+
const res4 = await client.bf.mAdd('bikes:models', [
25+
'Rocky Mountain Racer',
26+
'Cloudy City Cruiser',
27+
'Windy City Wippet'
28+
]);
29+
console.log(res4); // >>> [true, true, true]
30+
31+
const res5 = await client.bf.mExists('bikes:models', [
32+
'Rocky Mountain Racer',
33+
'Cloudy City Cruiser',
34+
'Windy City Wippet'
35+
]);
36+
console.log(res5); // >>> [true, true, true]
37+
// STEP_END
38+
39+
// REMOVE_START
40+
assert.equal(res1, 'OK')
41+
assert.equal(res2, true)
42+
assert.equal(res3, true)
43+
assert.deepEqual(res4, [true, true, true])
44+
assert.deepEqual(res5, [true, true, true])
45+
await client.quit();
46+
// REMOVE_END

doctests/dt-cms.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// EXAMPLE: cms_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 cms
15+
const res1 = await client.cms.initByProb('bikes:profit', 0.001, 0.002);
16+
console.log(res1); // >>> OK
17+
18+
const res2 = await client.cms.incrBy('bikes:profit', {
19+
item: 'Smoky Mountain Striker',
20+
incrementBy: 100
21+
});
22+
console.log(res2); // >>> [100]
23+
24+
const res3 = await client.cms.incrBy('bikes:profit', [
25+
{
26+
item: 'Rocky Mountain Racer',
27+
incrementBy: 200
28+
},
29+
{
30+
item: 'Cloudy City Cruiser',
31+
incrementBy: 150
32+
}
33+
]);
34+
console.log(res3); // >>> [200, 150]
35+
36+
const res4 = await client.cms.query('bikes:profit', 'Smoky Mountain Striker');
37+
console.log(res4); // >>> [100]
38+
39+
const res5 = await client.cms.info('bikes:profit');
40+
console.log(res5.width, res5.depth, res5.count); // >>> 2000 9 450
41+
// STEP_END
42+
43+
// REMOVE_START
44+
assert.equal(res1, 'OK')
45+
assert.deepEqual(res2, [100])
46+
assert.deepEqual(res3, [200, 150])
47+
assert.deepEqual(res4, [100])
48+
assert.deepEqual(res5, { width: 2000, depth: 9, count: 450 })
49+
await client.quit();
50+
// REMOVE_END

doctests/dt-cuckoo.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// EXAMPLE: cuckoo_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 cuckoo
15+
const res1 = await client.cf.reserve('bikes:models', 1000000);
16+
console.log(res1); // >>> OK
17+
18+
const res2 = await client.cf.add('bikes:models', 'Smoky Mountain Striker');
19+
console.log(res2); // >>> 1
20+
21+
const res3 = await client.cf.exists('bikes:models', 'Smoky Mountain Striker');
22+
console.log(res3); // >>> 1
23+
24+
const res4 = await client.cf.exists('bikes:models', 'Terrible Bike Name');
25+
console.log(res4); // >>> 0
26+
27+
const res5 = await client.cf.del('bikes:models', 'Smoky Mountain Striker');
28+
console.log(res5); // >>> 1
29+
// STEP_END
30+
31+
// REMOVE_START
32+
assert.equal(res1, 'OK')
33+
assert.equal(res2, true)
34+
assert.equal(res3, true)
35+
assert.equal(res4, false)
36+
assert.equal(res5, true)
37+
await client.quit();
38+
// REMOVE_END

doctests/dt-hll.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// EXAMPLE: hll_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 pfadd
15+
const res1 = await client.pfAdd('bikes', ['Hyperion', 'Deimos', 'Phoebe', 'Quaoar']);
16+
console.log(res1); // >>> true
17+
18+
const res2 = await client.pfCount('bikes');
19+
console.log(res2); // >>> 4
20+
21+
const res3 = await client.pfAdd('commuter_bikes', ['Salacia', 'Mimas', 'Quaoar']);
22+
console.log(res3); // >>> true
23+
24+
const res4 = await client.pfMerge('all_bikes', ['bikes', 'commuter_bikes']);
25+
console.log(res4); // >>> OK
26+
27+
const res5 = await client.pfCount('all_bikes');
28+
console.log(res5); // >>> 6
29+
// STEP_END
30+
31+
// REMOVE_START
32+
assert.equal(res1, true)
33+
assert.equal(res2, 4)
34+
assert.equal(res3, true)
35+
assert.equal(res4, 'OK')
36+
assert.equal(res5, 6)
37+
await client.quit();
38+
// REMOVE_END

0 commit comments

Comments
 (0)