Skip to content

API

pico_data_redis.factory

Provides a shared redis.Redis client built from RedisSettings.

RedisLifecycle

Closes the shared client's connection pool on container shutdown.

Source code in src/pico_data_redis/factory.py
@component
class RedisLifecycle:
    """Closes the shared client's connection pool on container shutdown."""

    def __init__(self, client: Redis):
        self._client = client

    @cleanup
    def close(self) -> None:
        self._client.close()

pico_data_redis.cache_backend

Distributed cache backend for pico-caching.

Satisfies pico-caching's CacheBackend Protocol structurally — no import of pico-caching needed. Installing pico-data-redis next to pico-caching makes @cacheable distributed: the interceptor prefers any non-in-memory backend it finds in the container.

Values are pickled: @cacheable caches arbitrary Python results. That makes the cache trusted storage — anyone who can write to Redis can execute code in consumers. Keep it on a private instance, as with celery result backends.

pico_data_redis.config

Settings for pico-data-redis (prefix redis, zero-config).

RedisSettings dataclass

Installing pico-data-redis opts the app into Redis: the client and the cache backend activate with these defaults.

Source code in src/pico_data_redis/config.py
@configured(target="self", prefix="redis", mapping="tree")
@dataclass
class RedisSettings:
    """Installing pico-data-redis opts the app into Redis: the client and the
    cache backend activate with these defaults."""

    url: str = "redis://localhost:6379/0"
    socket_timeout_seconds: float = 5.0
    cache_prefix: str = "pico:cache:"