Node-redis: client.set expire

Created on 15 Feb 2019  路  1Comment  路  Source: NodeRedis/node-redis

I have been using the cache so far in this way

self.client.set(key, value, 'EX', _expire, function(err, res) {
                // res is null when the key is missing
                if(err) self.logger.error("RedisStore.set err %@", err);
                else self.logger.debug("RedisStore.set %@", key);
                return callback(err, res);
            }); 

passing the EX, and setting a variable expressed in seconds.
I see from tests that it is used in a different way

client.set(['ttl key', 'ttl val'], helper.isString('OK'));
                client.expire(['ttl key', '100'], helper.isNumber(1));
                client.TTL(['ttl key'], function (err, ttl) {
                    assert(ttl >= 99);
                    assert(ttl <= 100);
                    done(err);
                });

Which is the correct way in the current version?

question

>All comments

Both are OK. This is independent from node_redis and just how Redis itself works. Please do not ask generic Redis questions here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

betimer picture betimer  路  5Comments

ghost picture ghost  路  3Comments

strumwolf picture strumwolf  路  4Comments

abhaygarg picture abhaygarg  路  5Comments

adamgajzlerowicz picture adamgajzlerowicz  路  4Comments