def test_exists(self): key = 'dqtest-{}'.format(uuid4()) assert not Redis.exists(key) Redis.set(key, '1') assert Redis.exists(key) assert Redis.delete(key) assert not Redis.exists(key)
def test_atomic_rw_user_abort(self): def evaluator(x): return None Redis.set('dqtest-rw', 'meow') success, no_error = Redis.atomic_rw('dqtest-rw', evaluator) assert not success and no_error assert Redis.get('dqtest-rw') == 'meow' Redis.delete('dqtest-rw')
def test_atomic_rw(self): def evaluator(x): return x + '#1' Redis.set('dqtest-rw', 'cornell ') success, no_error = Redis.atomic_rw('dqtest-rw', evaluator) assert success and no_error assert Redis.get('dqtest-rw') == 'cornell #1' Redis.delete('dqtest-rw')
def test_atomic_rw_error(self): def change(): Redis.set('dqtest-rw', 'cornell') def evaluator(x): t = threading.Thread(target=change) t.start() sleep(0.5) return x + '#1' Redis.set('dqtest-rw', 'meow') success, no_error = Redis.atomic_rw('dqtest-rw', evaluator) assert not success and not no_error assert Redis.get('dqtest-rw') == 'cornell' Redis.delete('dqtest-rw')
def test_expire(self): key = 'dqtest-{}'.format(uuid4()) assert Redis.set(key, '1') assert Redis.expire(key, 1) sleep(1.5) assert not Redis.exists(key)
def change(): Redis.set('dqtest-rw', 'cornell')