Skip to content

Instantly share code, notes, and snippets.

@aita
Created September 29, 2011 00:55
Show Gist options
  • Save aita/1249736 to your computer and use it in GitHub Desktop.
Save aita/1249736 to your computer and use it in GitHub Desktop.
Memcache Lock
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