Skip to main content

Redis connection building blocks for the fastfoundry ecosystem.

Project description

fastfoundry-redis

Redis connection building blocks for the fastfoundry ecosystem.

Part of the fastfoundry.* namespace (fastfoundry-settings, fastfoundry-postgres, …).

An async redis-py connection pool and client lifecycle for a single Redis server, and a configuration model that plugs into fastfoundry.settings.

Install

pip install fastfoundry-redis
# or
uv add fastfoundry-redis

Requires Python 3.12+.

Configuration

RedisCfg holds the connection parameters. It is designed to nest inside a fastfoundry.settings.BaseAppSettings subclass, so the values load from the environment with the rest of your service configuration, then get handed to redis_pool_ctx:

from fastfoundry.settings import BaseAppSettings
from fastfoundry.redis import RedisCfg


class Settings(BaseAppSettings):
    redis: RedisCfg


settings = Settings()

With the FF_ prefix and __ nested delimiter that BaseAppSettings applies, the fields are read from the environment as FF_REDIS__HOST, FF_REDIS__PORT, FF_REDIS__DB, and so on. password is optional (omit it for a server without auth).

Connection pool & client lifecycle

Open redis_pool_ctx(settings.redis) once for the application lifetime — it builds the connection pool, publishes it for ambient access (get_pool() and redis_cfg()), and disconnects it on exit. For FastAPI, wire it into the lifespan:

from contextlib import asynccontextmanager
from collections.abc import AsyncGenerator

from fastapi import FastAPI
from fastfoundry.redis import redis_pool_ctx

from app.settings import settings


@asynccontextmanager
async def lifespan(_: FastAPI) -> AsyncGenerator[None, None]:
    async with redis_pool_ctx(settings.redis):
        yield


app = FastAPI(lifespan=lifespan)

Acquire a client with redis_client; it draws a connection from the pool and returns it on exit. Responses are decoded to str by default (decode_responses=True):

from fastfoundry.redis import redis_client


async with redis_client() as rc:
    await rc.set("key", "value")
    value = await rc.get("key")

Development

mise run install     # uv sync --dev
mise run lint        # ruff check
mise run typecheck   # mypy --strict
mise run test        # pytest
mise run build       # uv build (sdist + wheel)

License

MIT

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

fastfoundry_redis-1.0.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastfoundry_redis-1.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file fastfoundry_redis-1.0.1.tar.gz.

File metadata

  • Download URL: fastfoundry_redis-1.0.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastfoundry_redis-1.0.1.tar.gz
Algorithm Hash digest
SHA256 12deeb93c040d8eace8449ad81bf2dfbbf95e034853cba8789adc71c32e595fb
MD5 35226f89ef196d962882f3c984cebf68
BLAKE2b-256 0765d322ef69489915c678978d65cc606f973429e4366ef3c4370480f8935330

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastfoundry_redis-1.0.1.tar.gz:

Publisher: release.yml on Drozdetskiy/fastfoundry-redis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastfoundry_redis-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fastfoundry_redis-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ba725e57db7ec6f591812d507c0174247f20c705f3aa95bb82a213c87c694e22
MD5 ad131524fc355c9ad0094cd0509718b8
BLAKE2b-256 377ddf9a82c560e0479d8e0f56c086c5a02845b79246b0e85f5d82fdc384ad1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastfoundry_redis-1.0.1-py3-none-any.whl:

Publisher: release.yml on Drozdetskiy/fastfoundry-redis

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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