Created
January 22, 2023 14:36
-
-
Save Prosen-Ghosh/b4937938bba11d2dff783af2be202316 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(); | |
// Acquire lock | |
const lock = await redis.set("lock:resource", "locked", "EX", 10, "NX"); | |
if (lock === "OK") { | |
// Do something with the resource | |
console.log("Lock acquired"); | |
// Release lock | |
await redis.del("lock:resource"); | |
} else { | |
console.log("Lock not acquired"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment