valkey-py icon indicating copy to clipboard operation
valkey-py copied to clipboard

Suggestion: Add max_tries to transaction()

Open haukex opened this issue 1 month ago • 7 comments

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.

haukex avatar Nov 04 '25 11:11 haukex