In redis, I have a hash where I want to first get and then set a value. I reckon I can use pipelining to speed up the whole operation via downsizing the round trips, like so:
my_pipeline = redis.Redis(connection_pool=POOL).pipeline()
my_pipeline.hget("my_hash","my_time")
my_pipeline.hset("my_hash","my_time",latest_time)
result = my_pipeline.execute()
old_value_of_my_time = result[0]
Essentially I've tried to retrieve the original value of my_time
for later use, and then set a new value.
So the question is: is doing hget
and hset
on the same value in the same pipeline correct? I understand from this SO post (and general knowledge of pipelines) that the order of commands is preserved in pipelines. So ostensibly, my approach should be correct.
However I might be missing something, so can an expert vet this approach?
Note: I've used python syntax in the example code. Moreover, if I wasn't using a hash, I'd simply use getset
for this operation. But note that I must use a hash in this case - for reasons outside the scope of this question.