-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathdt-cms.js
50 lines (42 loc) · 1.17 KB
/
dt-cms.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// EXAMPLE: cms_tutorial
// HIDE_START
import assert from 'assert';
import { createClient } from 'redis';
const client = createClient();
await client.connect();
// HIDE_END
// REMOVE_START
await client.flushDb();
// REMOVE_END
// STEP_START cms
const res1 = await client.cms.initByProb('bikes:profit', 0.001, 0.002);
console.log(res1); // >>> OK
const res2 = await client.cms.incrBy('bikes:profit', {
item: 'Smoky Mountain Striker',
incrementBy: 100
});
console.log(res2); // >>> [100]
const res3 = await client.cms.incrBy('bikes:profit', [
{
item: 'Rocky Mountain Racer',
incrementBy: 200
},
{
item: 'Cloudy City Cruiser',
incrementBy: 150
}
]);
console.log(res3); // >>> [200, 150]
const res4 = await client.cms.query('bikes:profit', 'Smoky Mountain Striker');
console.log(res4); // >>> [100]
const res5 = await client.cms.info('bikes:profit');
console.log(res5.width, res5.depth, res5.count); // >>> 2000 9 450
// STEP_END
// REMOVE_START
assert.equal(res1, 'OK')
assert.deepEqual(res2, [100])
assert.deepEqual(res3, [200, 150])
assert.deepEqual(res4, [100])
assert.deepEqual(res5, { width: 2000, depth: 9, count: 450 })
await client.quit();
// REMOVE_END