I want to set multiple keys with an expire time, but it seems I have to expire every keys one by one.Why do not Redis provide an operation just like "mset"?
Having multiple keys point to same value is not supported in Redis for now, see issue #2668. You would need a workaround. You could implement that logic in your client code, or in custom Lua scripts on server, and have your client code use those scripts (but I don't know enough about that to provide details).
Normally Redis keys are created without an associated time to live. The key will simply live forever, unless it is removed by the user in an explicit way, for instance using the DEL command.
All the Redis objects have an expiration time. By default, the value is set to never. However, by changing this value, we can set Redis keys that will expire automatically after a fixed amount of time. Once the expiration time is passed, the key is deleted from the database.
You can use one script as it.
EVAL 'for i, name in ipairs(redis.call("KEYS", "0*")) do redis.call("EXPIRE", name, 10); end' 0
Because this operation is not so frequent and you can easily simulate it by:
or
Whatever the chosen solution, it will only generate a single roundtrip to the redis server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With