You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
DOC-3933: final 8 tabbed code examples (#2784)
This commit is contained in:
76
doctests/dt-bitfield.js
Normal file
76
doctests/dt-bitfield.js
Normal file
@@ -0,0 +1,76 @@
|
||||
// EXAMPLE: bitfield_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 bf
|
||||
let res1 = await client.bitField("bike:1:stats", [{
|
||||
operation: 'SET',
|
||||
encoding: 'u32',
|
||||
offset: '#0',
|
||||
value: 1000
|
||||
}]);
|
||||
console.log(res1); // >>> [0]
|
||||
|
||||
let res2 = await client.bitField('bike:1:stats', [
|
||||
{
|
||||
operation: 'INCRBY',
|
||||
encoding: 'u32',
|
||||
offset: '#0',
|
||||
increment: -50
|
||||
},
|
||||
{
|
||||
operation: 'INCRBY',
|
||||
encoding: 'u32',
|
||||
offset: '#1',
|
||||
increment: 1
|
||||
}
|
||||
]);
|
||||
console.log(res2); // >>> [950, 1]
|
||||
|
||||
let res3 = await client.bitField('bike:1:stats', [
|
||||
{
|
||||
operation: 'INCRBY',
|
||||
encoding: 'u32',
|
||||
offset: '#0',
|
||||
increment: 500
|
||||
},
|
||||
{
|
||||
operation: 'INCRBY',
|
||||
encoding: 'u32',
|
||||
offset: '#1',
|
||||
increment: 1
|
||||
}
|
||||
]);
|
||||
console.log(res3); // >>> [1450, 2]
|
||||
|
||||
let res4 = await client.bitField('bike:1:stats', [
|
||||
{
|
||||
operation: 'GET',
|
||||
encoding: 'u32',
|
||||
offset: '#0'
|
||||
},
|
||||
{
|
||||
operation: 'GET',
|
||||
encoding: 'u32',
|
||||
offset: '#1'
|
||||
}
|
||||
]);
|
||||
console.log(res4); // >>> [1450, 2]
|
||||
// STEP_END
|
||||
|
||||
// REMOVE_START
|
||||
assert.deepEqual(res1, [0])
|
||||
assert.deepEqual(res2, [950, 1])
|
||||
assert.deepEqual(res3, [1450, 2])
|
||||
assert.deepEqual(res4, [1450, 2])
|
||||
await client.quit();
|
||||
// REMOVE_END
|
Reference in New Issue
Block a user