Reputation: 2451
Project page: https://github.com/NodeRedis/node_redis
It's possible to set an expiration for a key with:
client.set('key', 'value!', 'EX', 10);
Is there a way to get (read) the expiration of am existing key?
Upvotes: 2
Views: 10777
Reputation: 354
You can use ttl function to get the remaining time until a key is expired. Note that you should promisify the function or use callbacks to get the result. An example code block in an async function would be like this:
const { promisify } = require('util');
const ttl = promisify(client.ttl).bind(client);
client.set('key', 'value!', 'EX', 10);
const remaingTime = await ttl('key');
Upvotes: 6