示例#1
0
def test_set_to_cache(rdc: RedisCache) -> None:
    key = "teste:1"
    value = 10
    rdc.set_to_cache(key, value)
    cache = pickle.loads(rdc.get(key))
    assert cache
    assert cache == 10

    rdc.delete(key)
示例#2
0
def test_get_from_cache(rdc: RedisCache) -> None:
    key = "teste:2"
    value = 20
    rdc.setex(key, timedelta(seconds=3600), value=pickle.dumps(value))
    cache = rdc.get_from_cache(key)
    assert cache
    assert cache == value

    rdc.delete(key)
示例#3
0
def test_invalidate_cache(rdc: RedisCache) -> None:
    key = "teste:4"
    value = 20
    rdc.setex(key, timedelta(seconds=3600), value=pickle.dumps(value))
    cache = rdc.get(key)
    assert cache
    rdc.invalidate_cache(key)
    cache = rdc.get(key)
    assert cache is None

    rdc.delete(key)
示例#4
0
def test_get_from_cache_none(rdc: RedisCache) -> None:
    key = "teste:3"
    cache = rdc.get_from_cache(key)
    assert cache is None

    rdc.delete(key)