Unable to call expireTime(), expireAt() not working as expected,
Description
In my code I want a particular to key to expire at the end of the day. I do this as follows:
const todayEnd = new Date().setHours(23, 59, 59, 999);
await redis.expireAt(MY_KEY, todayEnd);
However the key does not expire at the end of the day as expected. I also get as error when I try to query the expiry time of my key as follows:
const expiryTime = await redis.expireTime(waveForecastDataKey);
which gives me the following error:
[ErrorReply: ERR unknown command EXPIRETIME, with args beginning with: MY_KEY, ]
I get the same error if I set an expiry time in seconds with the expire() function. This method however does cause the key to expire in the expected number of seconds.
Node.js Version
18.16.1
Redis Server Version
6.2.6
Node Redis Version
^4.6.7
Platform
macOS
Logs
[ErrorReply: ERR unknown command `EXPIRETIME`, with args beginning with: `waveForecastDataKey`, ]
Try formatting it in the "raw Redis commands" manner. I had the same problem with EXPIRE, and using the raw syntax worked for me.
From the docs:
There is built-in support for all of the out-of-the-box Redis commands. They are exposed using the raw Redis command names (HSET, HGETALL, etc.) and a friendlier camel-cased version (hSet, hGetAll, etc.):
// raw Redis commands await client.HSET('key', 'field', 'value'); await client.HGETALL('key');
// friendly JavaScript commands await client.hSet('key', 'field', 'value'); await client.hGetAll('key');
Unfortunately I get the same error when using the raw EXPIRETIME command.
I am able to get a timestamp response when using the ttl function, however this always seems to wrong compared to what was set.
EXPIRETIMEwas added in Redis 7.0... You can use theTTLcommand instead (which will return the remaining TTL for the key).- I didn't play with it yet (I'll do it later), but I'm pretty sure that if the node server and the Redis server clocks are not synchronized (even if it's just a timezone difference) the expiration time will be off by the offset.