Skip to main content

Redis async utilities: cache, streams, consumer groups, and health checks

Project description

ulfblk-redis

Redis async utilities: cache, streams with consumer groups, and health checks.

Features

  • RedisManager - Connection lifecycle, async context manager, tenant-aware key prefixing
  • RedisCache - Key-value cache with TTL, JSON serialization, @cached decorator
  • StreamProducer / StreamConsumer - Redis Streams with consumer groups, auto-claim pending messages
  • Health check - Compatible with ulfblk-core HealthResponse.checks

Installation

uv add ulfblk-redis

Quick Start

Cache

from ulfblk_redis.client import RedisManager, RedisSettings
from ulfblk_redis.cache import RedisCache, cached

settings = RedisSettings(url="redis://localhost:6379/0", key_prefix="myapp")

async with RedisManager(settings) as manager:
    cache = RedisCache(manager, default_ttl=300)

    await cache.set("user:1", {"name": "Alice"})
    user = await cache.get("user:1")  # {"name": "Alice"}

    # Decorator
    @cached(cache, ttl=60)
    async def get_user(user_id: str) -> dict:
        return await db.fetch_user(user_id)

Streams

from ulfblk_redis.client import RedisManager
from ulfblk_redis.streams import StreamProducer, StreamConsumer

async with RedisManager() as manager:
    producer = StreamProducer(manager, stream="events")
    await producer.publish({"action": "signup", "user": "alice"})

    consumer = StreamConsumer(
        manager, stream="events", group="workers", consumer_name="w1"
    )
    await consumer.ensure_group()

    async for msg in consumer.listen():
        print(msg.data)
        await consumer.ack(msg.message_id)

Multitenant

# Automatic tenant prefixing (soft dependency on ulfblk-multitenant)
settings = RedisSettings(key_prefix="app", tenant_aware=True)
manager = RedisManager(settings)

# With ulfblk_multitenant context active (tenant_id="t1"):
# manager.make_key("session:abc") -> "app:t1:session:abc"

# Or explicit:
# manager.make_key("session:abc", tenant_id="t1") -> "app:t1:session:abc"

Health Check

from ulfblk_redis.health import redis_health_check

checks = await redis_health_check(manager)
# {"redis": True}

Dependencies

  • ulfblk-core - Logging, health response schemas
  • redis[hiredis]>=5.0 - Async Redis client

Development

uv sync --all-packages --all-extras
uv run pytest packages/python/ulfblk-redis -v

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

ulfblk_redis-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

ulfblk_redis-0.1.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file ulfblk_redis-0.1.0.tar.gz.

File metadata

  • Download URL: ulfblk_redis-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ulfblk_redis-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a9d7361b2779683bd3d2e258ad4441f27d86747fb80164c08843cb3d54d25b77
MD5 66a180a32497bc641efa99155178d09b
BLAKE2b-256 e88cd26483d82d514e13d43df47f8cbcaf4d279f9e6377139034c45d573ff0ea

See more details on using hashes here.

File details

Details for the file ulfblk_redis-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ulfblk_redis-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for ulfblk_redis-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5ec9cf7d8982e9bea06988867b05b0dec74e327f79bcc3851e43821125faeed
MD5 93f54a8bcfa02cee3ff4bd67d21c67c3
BLAKE2b-256 d2f5522ceb6a3b62721b88141e72df90339bc7eda2ad82e612a8a8cb89ef4ce0

See more details on using hashes here.

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