valkey-py
valkey-py copied to clipboard
Suggestion: Add max_tries to transaction()
Hi, I would like to propose that the transaction() helper gets an additional argument max_tries (perhaps even with a default value) to prevent infinite loops, as can happen fairly easily by accident:
vk = Valkey()
def incr(pipe: Pipeline):
next_value = int(pipe.get('key')) + 1
pipe.multi()
vk.set('key', next_value) # WRONG!
vk.transaction(incr, 'key', max_tries=100) # would eventually raise error instead of infinite loop
If you like this change, I can also suggest some documentation updates etc. if you like.