Skip to content

Instantly share code, notes, and snippets.

@Prosen-Ghosh
Created January 22, 2023 14:30
Show Gist options
  • Save Prosen-Ghosh/f2d6eecab9b166ea55bba4494fe7d877 to your computer and use it in GitHub Desktop.
Save Prosen-Ghosh/f2d6eecab9b166ea55bba4494fe7d877 to your computer and use it in GitHub Desktop.
const Redis = require("ioredis");
const redis = new Redis();
redis.get("page:home").then(cacheData => {
if (cacheData) {
console.log(JSON.parse(cacheData));
} else {
// Fetch data from database
const data = await fetchDataFromDb();
// set cache data for page
redis.set("page:home", JSON.stringify(data));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment