Here is my code:
const Redis = require('ioredis');
const client = new Redis();
// multi set
client.mset({'key1': 'value1'});
Question is does mset
operation accept options to set TTL
like set
command does?
// sample for set
client.set(key, value, 'EX', 10);
No it does not.
MSET
is used forjust
for setting multiple values for the keys. As you may can see here from the implementation, there is no option to set expiration for the keys. Another variation MSETNX also does not support optional expiration.You need to execute
EXPIRE
command for each key you set inMSET
. Another option could be executing them in transaction or completely discardingMSET
but useSETEX
(orSET
withEX
option) for each key.