This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import hashlib | |
| import hmac | |
| def digest_data(data): | |
| if type(data) == list: | |
| return "[%s]" % (",".join([digest_data(v) for v in data if v])) | |
| elif type(data) == dict: | |
| kvs = sorted(data.items(), lambda x,y: cmp(x[0],y[0])) | |
| def prefix(key): | |
| return "" if type(key) == int else "%s:" % key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def acquire(name): | |
| tries = 0 | |
| while True: | |
| tries += 1 | |
| if tries >= 30: | |
| raise Exception("Couldn't acquire lock on mutex "+name) | |
| try: | |
| n = r.incr("lock-"+name) | |
| if n == 1: | |
| return True |