Created
January 22, 2023 14:50
-
-
Save Prosen-Ghosh/4db5574647db17b26c04dccccc2087e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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