Hi, I am using pipe to update bulk of keys. However the same key can be updated from multiple processes at once
and i want to make sure that if it happens i get the value again and update it including the other changes - perform a merge.
I saw that watch feature can do this as shown in the following example. However i need to know which key failed since another client changed it. But the WatchError does not hold this information.
Is there another way to merge like this or extract this information from watch?
Thanks
with redis_server.pipeline() as pipe:
while 1:
try:
# put a WATCH on the key that holds our sequence value
pipe.watch('key1', 'key2')
# after WATCHing, the pipeline is put into immediate execution
# mode until we tell it to start buffering commands again.
# this allows us to get the current value of our sequence
current_value = pipe.get('key1')
if current_value is None:
next_value = 1
else:
next_value = int(current_value) + 1
current_value2 = pipe.get('key2')
if current_value2 is None:
next_value2 = 1
else:
next_value2 = int(current_value2) + 1
# now we can put the pipeline back into buffered mode with MULTI
pipe.multi()
pipe.set('key1', next_value)
pipe.set('key2', next_value2)
# and finally, execute the pipeline (the set command)
pipe.execute()
# if a WatchError wasn't raised during execution, everything
# we just did happened atomically.
break
except WatchError as e: