1

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);
Ersoy
  • 8,816
  • 6
  • 34
  • 48
jagadeesh m
  • 73
  • 2
  • 9

1 Answers1

1

No it does not. MSET is used for just 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 in MSET. Another option could be executing them in transaction or completely discarding MSET but use SETEX(or SET with EX option) for each key.

Ersoy
  • 8,816
  • 6
  • 34
  • 48
  • 1
    thanks for the information. I figured it out that way from documentation, It is annoying why they won't allow to set the expiry on multi key select. – jagadeesh m Feb 07 '21 at 16:48