Created
January 22, 2023 14:30
-
-
Save Prosen-Ghosh/f2d6eecab9b166ea55bba4494fe7d877 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(); | |
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