def test_hash(self): key = 'dqtest-{}'.format(uuid4()) assert not Redis.hgetall(key) assert not Redis.hget(key, '1') assert Redis.hset(key, '1', '1') assert Redis.hget(key, '1') == '1' assert Redis.hset(key, '2', '3') assert Redis.hget(key, '2') == '3' assert Redis.hset(key, '3', {'cornell': '#1'}) assert Redis.hget(key, '3') == '{"cornell": "#1"}' assert Redis.hgetall(key) == { '1': '1', '2': '3', '3': '{"cornell": "#1"}' } assert Redis.hdelete(key, '1') assert Redis.hgetall(key) == {'2': '3', '3': '{"cornell": "#1"}'} assert Redis.delete(key) assert not Redis.exists(key)
def test_atomic_rw_hash_user_abort(self): def evaluator(x): return None Redis.hset('dqtest-rwh', 'key', 'meow') succ, no_error = Redis.atomic_rw_hash('dqtest-rwh', 'key', evaluator) assert not succ and no_error assert Redis.hget('dqtest-rwh', 'key') == 'meow' Redis.delete('dqtest-rwh')
def test_atomic_rw_hash(self): def evaluator(x): return x + '#1' Redis.hset('dqtest-rwh', 'key', 'cornell ') succ, no_error = Redis.atomic_rw_hash('dqtest-rwh', 'key', evaluator) assert succ and no_error assert Redis.hget('dqtest-rwh', 'key') == 'cornell #1' Redis.delete('dqtest-rwh')
def test_atomic_rw_hash_error(self): def change(): Redis.hset('dqtest-rwh', 'key', 'meow2') def evaluator(x): t = threading.Thread(target=change) t.start() sleep(0.5) return x + '#1' Redis.hset('dqtest-rwh', 'key', 'meow') succ, no_error = Redis.atomic_rw_hash('dqtest-rwh', 'key', evaluator) assert not succ and not no_error assert Redis.hget('dqtest-rwh', 'key') == 'meow2' Redis.delete('dqtest-rwh')