Created
September 29, 2011 00:55
-
-
Save aita/1249736 to your computer and use it in GitHub Desktop.
Memcache Lock
This file contains 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
class MemcacheLock(object): | |
""" | |
memcacheのLockオブジェクト | |
""" | |
LOCK_CACHE_VALUE = 'ALL' | |
def __init__(self, cache, key): | |
self.cache = cache | |
self.key = key | |
def acquire(self): | |
""" | |
ブロックあり、またはブロックなしでロックを獲得します | |
""" | |
v = self.get(self.key) | |
if v is None: | |
self.set(self.key, self.LOCK_CACHE_VALUE) | |
return True | |
return False | |
def release(self): | |
""" | |
ロックを解放します | |
""" | |
self.cache.delete(self.key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment