RedisStrategy (strategy/redis.py)

fastapi-users · fastapi_users/authentication/strategy/redis.py · python · MIT
database

A Redis-backed authentication strategy that manages user tokens by storing them in a Redis database for fast retrieval and expiration.

# Source: https://github.com/fastapi-users/fastapi-users | License: MIT | Copyright 2019 François Voron
# Provided via justclaw.it.com; keep this notice with the code.
import secrets
from typing import Generic

import redis.asyncio

from fastapi_users import exceptions, models
from fastapi_users.authentication.strategy.base import Strategy
from fastapi_users.manager import BaseUserManager


class RedisStrategy(Strategy[models.UP, models.ID], Generic[models.UP, models.ID]):
    def __init__(
        self,
        redis: redis.asyncio.Redis,
        lifetime_seconds: int | None = None,
        *,
        key_prefix: str = "fastapi_users_token:",
    ):
        self.redis = redis
        self.lifetime_seconds = lifetime_seconds
        self.key_prefix = key_prefix

    async def read_token(
 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key