Exemplo n.º 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)
Exemplo n.º 2
0
def list_providers(
    user: UserModel = Depends(deps.get_user), 
    db: Session = Depends(deps.get_db),
    rdc: RedisCache = Depends(deps.get_redis)
) -> Any:
    """
    Endpoint for list providers
    """
    cache_key = f"providers-list:{str(user.id)}"
    providers = rdc.get_from_cache(cache_key)
    if not providers:
        providers = crud_user.get_all_providers(db, user)
        rdc.set_to_cache(cache_key, providers)

    return providers
Exemplo n.º 3
0
def list_self_provider_appointments(
    query: ProviderAppointmentsQuery = Depends(),
    user: UserModel = Depends(deps.get_user), 
    db: Session = Depends(deps.get_db),
    rdc: RedisCache = Depends(deps.get_redis),
) -> Any:
    """
    Endpoint for list self provider appointments
    """
    cache_key = f"providers-appointments:{str(user.id)}:{query.year}:{query.month}:{query.day}"
    appointments = rdc.get_from_cache(cache_key)
    if not appointments:
        appointments = crud_appointment.get_appointments_by_DMY(db, query, user)
        rdc.set_to_cache(cache_key, parse_obj_as(List[ProviderAppointments], appointments))

    return appointments
Exemplo n.º 4
0
def list_self_provider_appointments(
        user: UserModel = Depends(deps.get_user),
        db: Session = Depends(deps.get_db),
        rdc: RedisCache = Depends(deps.get_redis),
) -> Any:
    """
    Endpoint for list self user appointments
    """
    cache_key = f"user-appointments:{str(user.id)}"
    appointments = rdc.get_from_cache(cache_key)
    if not appointments:
        appointments = crud_appointment.get_appointments_by_user(db, user)
        rdc.set_to_cache(cache_key,
                         parse_obj_as(List[UserAppointments], appointments))

    return appointments
Exemplo n.º 5
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)