Skip to content

Instantly share code, notes, and snippets.

@Prosen-Ghosh
Created January 22, 2023 14:50
Show Gist options
  • Save Prosen-Ghosh/4db5574647db17b26c04dccccc2087e5 to your computer and use it in GitHub Desktop.
Save Prosen-Ghosh/4db5574647db17b26c04dccccc2087e5 to your computer and use it in GitHub Desktop.
const Redis = require("ioredis");
const redis = new Redis();
app.get("/retention", async (req, res) => {
const userId = req.query.userId;
const timestamp = Date.now();
const bitmapKey = `user_login:${userId}`;
const offset = Math.floor(timestamp / (24 * 60 * 60 * 1000));
const retention = await redis.bitcount(bitmapKey, 0, offset);
res.send(`User retention: ${retention}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment