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.0.tar.gz (42.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.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastfoundry_redis-1.0.0.tar.gz
  • Upload date:
  • Size: 42.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.0.tar.gz
Algorithm Hash digest
SHA256 01427edf92d0862fb45de62a66f87ca03b1713c853f2d505a69b564701cc720c
MD5 41a1aea05943bab3afd4838af741edeb
BLAKE2b-256 f3fa582236fa2ce7d3dd63b590a0ad360685b763f238a4d1df0a028edadbf383

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastfoundry_redis-1.0.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastfoundry_redis-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e75252ac660d8543529960c829577781c5740029dca9c2ae0cd15fc13edb5bf4
MD5 f1d52e6c6533ac76b3fb03715a1ae943
BLAKE2b-256 03b61b59d1a2c241dfe10af5643dc95c14e031f80222cf979d62c432581b3f1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastfoundry_redis-1.0.0-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