From 55a3ccb8ac4c0fb1954558efc27a75ab40e21845 Mon Sep 17 00:00:00 2001 From: Justin Castilla Date: Tue, 24 Oct 2023 15:52:59 -0700 Subject: [PATCH] adds bitmap exmaple for node.js --- doctests/dt-bitmap.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 doctests/dt-bitmap.js diff --git a/doctests/dt-bitmap.js b/doctests/dt-bitmap.js new file mode 100644 index 00000000000..b8efb364d0d --- /dev/null +++ b/doctests/dt-bitmap.js @@ -0,0 +1,39 @@ +// EXAMPLE: bitmap_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 ping +const res1 = await client.setBit("pings:2024-01-01-00:00", 123, 1) +console.log(res1) // >>> 0 + +const res2 = await client.getBit("pings:2024-01-01-00:00", 123) +console.log(res2) // >>> 1 + +const res3 = await client.getBit("pings:2024-01-01-00:00", 456) +console.log(res3) // >>> 0 +// STEP_END + +// REMOVE_START +assert.equal(res1, 0) +// REMOVE_END + +// STEP_START bitcount +// HIDE_START +await client.setBit("pings:2024-01-01-00:00", 123, 1) +// HIDE_END +const res4 = await client.bitCount("pings:2024-01-01-00:00") +console.log(res4) // >>> 1 +// STEP_END +// REMOVE_START +assert.equal(res4, 1) +await client.quit(); +// REMOVE_END \ No newline at end of file