Exemple #1
0
def test_transaction1():
    redis = RedisUtils().get_connection()
    pipe = redis.pipeline()
    try:
        pipe.watch("mykey1", "mykey2")
        pipe.multi()
        assert pipe.set("mykey1", "myvalue1")
        assert pipe.set("mykey2", "myvalue2")
        time.sleep(10)
        pipe.execute()
        print redis.get("mykey1")
        print redis.get("mykey2")
    except WatchError as e:
        print e
    finally:
        pipe.reset()
        RedisUtils().release_connection(redis)
Exemple #2
0
def test_pipeline():
    redis = RedisUtils().get_connection()
    pipe = redis.pipeline()
    assert pipe.set("mykey1", "myvalue1")
    assert pipe.set("mykey2", "myvalue2")
    pipe.execute()
    assert redis.get("mykey1") == "myvalue1"
    assert redis.get("mykey2") == "myvalue2"
    RedisUtils().release_connection(redis)
Exemple #3
0
def test_getset():
    redis = RedisUtils().get_connection()
    assert redis.set("mykey", "myvalue")
    assert redis.get("mykey") == "myvalue"
    assert redis.get("nokey") is None
    RedisUtils().release_connection(redis)