I am using node-redis. I have a cron job that updates my db and I have redis cache that caches the db response.
The problem I’m having is that my cron job runs everyday at 12am, however I can only set redis cache to expire in x seconds from now. Is there a way to make node-redis cache expire everyday at 12am exactly. Thanks.
Code:
const saveResult = await SET_CACHE_ASYNC('cacheData', response, 'EX', 15);
2
Answers
yes, you can use https://redis.io/commands/expireat command, if you use https://www.npmjs.com/package/redis package as redis driver, code will be like this
Recently I had the same problem with an application. My work around was creating a new timespan based on the time difference between my set and expiration time. Here is my code:
Using the stack exchange lib for a 6 AM absolute expirition time the code looks like so:
I used C# but you should be able to do the trick in any language.