SETEX is a useful Redis command whereby one can set the value and expiry of a key in a single, atomic operation.
Is there an equivalent operation that atomically enables a person to retrieve the key's value and ttl? I know I can do it in a pipeline as well, but I'm asking whether something elegant like SETEX exists. If it matters, I'm using Redis 2.8.4.
AFAIK, there's no such command. However, you can wrap
GETandTTLinto a Lua script, to get both value and ttl in a single atomic call.Also, you CANNOT achieve that with pipeline. Because Redis DOES NOT guarantee that commands in pipeline are running atomically.