Beispiel #1
0
    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')
Beispiel #2
0
    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')
Beispiel #3
0
    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')
Beispiel #4
0
    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')
Beispiel #5
0
    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')
Beispiel #6
0
    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')
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #9
0
 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)