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.
MSETis used forjustfor 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
EXPIREcommand for each key you set inMSET. Another option could be executing them in transaction or completely discardingMSETbut useSETEX(orSETwithEXoption) for each key.