Beispiel #1
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)
Beispiel #2
0
def test_invalidate_cache_prefix(rdc: RedisCache) -> None:
    suffix = utils.random_lower_string()
    prefix = "teste:5"
    key = f"{prefix}:{suffix}"
    value = 30
    rdc.setex(key, timedelta(seconds=3600), value=pickle.dumps(value))
    cache = rdc.get(key)
    assert cache
    rdc.invalidate_cache_prefix(prefix)
    cache = rdc.get(key)
    assert cache is None
Beispiel #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)
Beispiel #4
0
def test_invalidate_cache_user(db: Session, rdc: RedisCache) -> None:
    user = utils.create_random_user(db)
    provider = utils.create_random_provider(db)
    appointment = utils.create_random_appointment(db, provider, user)
    provider.provider_appointments.append(appointment)
    key = f"user-appointments:{str(user.id)}"
    value = 40
    rdc.setex(key, timedelta(seconds=3600), value=pickle.dumps(value))
    cache = rdc.get(key)
    assert cache
    rdc.invalidate_cache_user(provider)
    cache = rdc.get(key)
    assert cache is None