Created
December 31, 2021 08:49
-
-
Save devAgam/8b298a958a63648f890e63472461abc9 to your computer and use it in GitHub Desktop.
How to delete a key/cached data from redis
This file contains hidden or 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
app.get("/sileo-depiction-revalidate/:package", async (req, res) => { | |
const dep_package = req.params.package; // package name | |
try { | |
const redisDepKey = `${dep_package}:depiction`; // redis key | |
return client.del(redisDepKey, async (err, success) => { // check if cached | |
if (success == 1) { // if success | |
res.status(200).send({ // send success acknowledgement | |
httpStatus: 200, | |
success: true, | |
success_binary: 1, | |
message: "Successfully deleted cached depiction", | |
meta_data: { | |
time_epoch = Math.floor(Date.now() / 1000), | |
time_iso = new Date().toISOString(), | |
} | |
}); | |
} else { // if failure | |
res.status(200).send({ // send failure acknowledgement | |
httpStatus: 200, | |
success: true, | |
success_binary: 1, | |
data: firestoreQueryNonce, | |
message: "could not delete cached depiction", | |
meta_data: { | |
time_epoch = Math.floor(Date.now() / 1000), | |
time_iso = new Date().toISOString(), | |
} | |
}); | |
} | |
}); | |
} catch (error) { // if error | |
console.log(error); | |
res.status(500).send({ // send error acknowledgement | |
httpStatus: 500, | |
success: false, | |
success_binary: 0, | |
data: null, | |
message: "could not delete data", | |
meta_data: { | |
time_epoch = Math.floor(Date.now() / 1000), | |
time_iso = new Date().toISOString(), | |
} | |
}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment