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

DOC-3933: final 8 tabbed code examples (#2784)

This commit is contained in:
David Dougherty
2024-07-03 12:29:13 -07:00
committed by GitHub
parent e7347f8a51
commit 0f3d0f3d1f
8 changed files with 543 additions and 0 deletions

48
doctests/dt-topk.js Normal file
View File

@@ -0,0 +1,48 @@
// EXAMPLE: topk_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 topk
const res1 = await client.topK.reserve('bikes:keywords', 5, {
width: 2000,
depth: 7,
decay: 0.925
});
console.log(res1); // >>> OK
const res2 = await client.topK.add('bikes:keywords', [
'store',
'seat',
'handlebars',
'handles',
'pedals',
'tires',
'store',
'seat'
]);
console.log(res2); // >>> [null, null, null, null, null, 'handlebars', null, null]
const res3 = await client.topK.list('bikes:keywords');
console.log(res3); // >>> ['store', 'seat', 'pedals', 'tires', 'handles']
const res4 = await client.topK.query('bikes:keywords', ['store', 'handlebars']);
console.log(res4); // >>> [1, 0]
// STEP_END
// REMOVE_START
assert.equal(res1, 'OK')
assert.deepEqual(res2, [null, null, null, null, null, 'handlebars', null, null])
assert.deepEqual(res3, ['store', 'seat', 'pedals', 'tires', 'handles'])
assert.deepEqual(res4, [1, 0])
await client.quit();
// REMOVE_END