andymccurdy/redis-py — Issue #218: stop while loop in transaction() 
Author: d5
Created: 2012-01-17 21:06:25+00:00
State: open

I love the idea of transaction() and pipeline(), and I'm using it pretty much.

But, I also hope that I can control the while loop in the implementation of transaction().
I mean, for example, if the function specified as the first argument of transaction() returns False, transaction() just breaks out of the loop.

For now, I'm achieving it using exception raising inside my function, but feel not safe :D

@classmethod
def update_user(cls, user)
ukey = ...

try:
def txn(pipe):
uid = g.user_db.get(ukey)
if uid is None:
raise Exception()

pipe.multi()
pipe.set('uid:{0}:name'.format(uid), user.name)
pipe.set('uid:{0}:email'.format(uid), user.email)

g.user_db.transaction(txn, ukey)
return True
except:
return False