Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC-2835 - Adds bitmap exmaple for node.js #2636

Open
wants to merge 1 commit into
base: emb-examples
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions 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