Skip to main content

redis 쉽게

Project description

FASTAPI REDIS

USAGE

from fastapi_redis import (
    FastAPIRedis,
    FastAPIAsyncRedis
)
from fastapi_redis.types import (
    RedisClient,
    AsyncRedisClient,
    FastAPIAsyncRedis,
    FastAPIRedis
) 
from fastapi import (
    FastAPI,
    Depends
)

app = FastAPI()

redis = FastAPIRedis(
    host="127.0.0.1",
    port="6379"
)

async_redis = FastAPIAsyncRedis(
    host="127.0.0.1",
    port="6379"
)

# In Depends
@app.get("/")
def get(
    rd: RedisClient = Depends(redis.get_connection)  
):
    rd.get("test")
    
    
@app.get('/')
async def get(
    rd: AsyncRedisClient = Depends(async_redis.get_connection)
):
    await rd.get("test")

    
# Outside of Depends
@app.get("/")
def get():
    conn: RedisClient
    with redis.get_connection_() as conn:
        conn.get("test")
    
@app.get("/")
async def get():
    conn: AsyncRedisClient
    async with async_redis.get_connection_() as conn:
        await conn.get("test")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_redis_vet1ments-0.2.6.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

fastapi_redis_vet1ments-0.2.6-py3-none-any.whl (5.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page