def test_get_json_string(self): key = 'dqtest-{}'.format(uuid4()) assert not Redis.get(key) Redis.setex(key, [1, '2', True], 1) assert Redis.get(key) == '[1, "2", true]' Redis.setex(key, {'cornell': '#1'}, 1) assert Redis.get(key) == '{"cornell": "#1"}'
def test_get(self): key = 'dqtest-{}'.format(uuid4()) assert not Redis.get(key) Redis.setex(key, '1', 1) assert Redis.get(key) == '1' assert Redis.delete(key) assert not Redis.get(key)
def test_get_json(self): key = 'dqtest-{}'.format(uuid4()) assert not Redis.get(key) Redis.setex(key, [1, '2', True], 1) assert Redis.get_json(key) == [1, '2', True] Redis.setex(key, {'cornell': '#1'}, 1) assert Redis.get_json(key) == {'cornell': '#1'}
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')