Reputation: 15824
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.
Upvotes: 2
Views: 2356
Reputation: 4677
You could use MULTI/EXEC
to make sure some commands being in a transaction. pipeline just save the network transport time(rtt), because it will send the request in a batch and recieve reply in a batch also.
You could refer Redis Transaction and pipelining for more details.
Upvotes: 3
Reputation: 22906
AFAIK, there's no such command. However, you can wrap GET
and TTL
into 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.
Upvotes: 3