Calculate the time to expire at the end of the current month with DayJs
Posted on October 29, 2021
If you want to set an expiration time to a Redis record that matches the end of the current month, here the snippet using Day.js:
const dayjs = require('dayjs')
const start = dayjs().unix()
const end = dayjs().endOf('month').unix()
const secondsToExpire = end - start
So, with ioRedis you can write something:
redis.set('record:that:expires:end:month', 'Some content', 'EX', secondsToExpire)