Skip to content

Commit

Permalink
Implement storage.get method
Browse files Browse the repository at this point in the history
  • Loading branch information
joealcorn committed Aug 19, 2015
1 parent f7b350e commit 27e1152
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions celery_dedupe/storage/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def __init__(self, connection, **config):
self.config = self.default_config.copy()
self.config.update(config)

def get(self, key):
'''
Responsible for getting the data associated with a lock
:returns string:
'''
raise NotImplementedError('Storages must implement get method')

def obtain_lock(self, key, value):
'''
Responsible for obtaining a lock for the task
Expand Down
3 changes: 3 additions & 0 deletions celery_dedupe/storage/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class RedisStorage(Storage):
'expiry': 0,
}

def get(self, key):
return self.connection.get(key)

def obtain_lock(self, key, value):
obtained = self.connection.setnx(key, value)
if self.config['expiry'] and obtained:
Expand Down
10 changes: 8 additions & 2 deletions tests/test_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ def test_lock_obtained_with_expiry(self):

def test_already_locked(self):
key = uuid4()
self.redis.setex(key, '1', 10)
self.redis.setex(key, 10, '1')
storage = RedisStorage(self.redis, expiry=10)
assert not storage.obtain_lock(key, '1')

def test_release_lock(self):
key = uuid4()
self.redis.setex(key, '1', 10)
self.redis.setex(key, 10, '1')
storage = RedisStorage(self.redis, expiry=10)
storage.release_lock(key)
assert not self.redis.get(key)

def test_get(self):
key = uuid4()
self.redis.setex(key, 10, '1')
storage = RedisStorage(self.redis)
assert storage.get(key) == '1'

0 comments on commit 27e1152

Please sign in to comment.