From 27e11528452739d034a78e3f3d9d9567f7ecc223 Mon Sep 17 00:00:00 2001 From: Joe Alcorn Date: Wed, 19 Aug 2015 10:52:57 +0100 Subject: [PATCH] Implement storage.get method --- celery_dedupe/storage/base.py | 7 +++++++ celery_dedupe/storage/redis.py | 3 +++ tests/test_storages.py | 10 ++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/celery_dedupe/storage/base.py b/celery_dedupe/storage/base.py index 1dada54..ef92fdd 100644 --- a/celery_dedupe/storage/base.py +++ b/celery_dedupe/storage/base.py @@ -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 diff --git a/celery_dedupe/storage/redis.py b/celery_dedupe/storage/redis.py index f9bed64..90ccd5e 100644 --- a/celery_dedupe/storage/redis.py +++ b/celery_dedupe/storage/redis.py @@ -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: diff --git a/tests/test_storages.py b/tests/test_storages.py index ad6738f..336e21f 100644 --- a/tests/test_storages.py +++ b/tests/test_storages.py @@ -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'