Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

node.js Redis refreshing expires for hset is not working

I'm using Redis 3.0.2 in node.js app. Iv'e added hset and then I set 'expire' command

async function updatePublisherTtl(publisherId, publisherSockets) {
    const logger = $log.child({method: 'updatePublisherTtl'});
    const publisherKey = `${LIVETAIL_REDIS_PREFIX}:${LOGS_BULK_PREFIX}:${publisherId}`;
    const publisherTtl = await redisClient.expire(publisherKey, 5);
    console.log(publisherTtl);
    if (!publisherTtl) {
        publisherSockets.forEach(function(socket) {
            socket.server.close();
        });
        logger.error("Failed to set TTL for publisher: {}, closing immediately the entire sockets for this Livetail publisher", publisherId);
    }
}

The expire has worked for the first time, after a second I expired again and it doesn't work. I expect that a key that already has an existing expiration set. In this case the time to live of a key is updated to the new value but the key has removed by redis even the function return true.

Refreshing expires - https://redis.io/commands/expire


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...