Skip to main content

OpenFrame Microservice Suite - Redis key-value adapter.

Project description

openframe-adapters-db-redis

Redis key-value adapter for the OpenFrame Microservice Development Suite.

Part of the openframe-adapters monorepo.


What it provides

Symbol Purpose
RedisSettings Pydantic-settings subclass — reads all config from env vars
RedisRepository[T] Generic async repository — BaseRepository[T] + HealthCheck
get_redis_client() Async factory — creates and caches the redis.asyncio.Redis client
RedisPlugin OpenFramePlugin — structured lifecycle via PluginRegistry

Installation

# Via meta-package (recommended)
pip install "openframe-adapters[redis]"

# Or directly
pip install openframe-adapters-db-redis

Quick start

from openframe.adapters.db.redis import RedisSettings, RedisRepository

settings = RedisSettings(redis_url="redis://localhost:6379/0")
repo = RedisRepository(settings)

# Store and retrieve
await repo.create({"id": "user-1", "name": "Alice"})
user = await repo.get("user-1")         # {"id": "user-1", "name": "Alice"}
await repo.update({"id": "user-1", "name": "Alice B."})
await repo.delete("user-1")             # True

Configuration

Env var Default Description
REDIS_URL required redis://[:password@]host[:port][/db] or rediss:// for TLS
REDIS_MAX_CONNECTIONS 10 Max connections in pool
REDIS_SOCKET_TIMEOUT 5.0 Socket read/write timeout (seconds)
REDIS_SOCKET_CONNECT_TIMEOUT 5.0 Connection timeout (seconds)
REDIS_KEY_PREFIX "openframe" Key namespace — keys stored as {prefix}:{id}
REDIS_DEFAULT_TTL 0 TTL in seconds; 0 = no expiry

Typed domain objects

from dataclasses import dataclass
from openframe.adapters.db.redis import RedisRepository, RedisSettings

@dataclass
class Session:
    id: str
    user_id: str
    token: str

class SessionRepository(RedisRepository[Session]):
    def _dict_to_entity(self, data: dict) -> Session:
        return Session(**data)
    def _entity_to_dict(self, entity: Session) -> dict:
        return {"id": entity.id, "user_id": entity.user_id, "token": entity.token}

Plugin lifecycle (optional)

from openframe.core.plugins import PluginRegistry
from openframe.adapters.db.redis import RedisPlugin, RedisSettings

registry = PluginRegistry()
registry.register(RedisPlugin(RedisSettings()))
await registry.initialize_all()

plugin = registry.get("cache")          # capability = "cache"
repo = plugin.get_repository()

License

MIT — © Furious Meteors Engineering

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

openframe_adapters_db_redis-1.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

openframe_adapters_db_redis-1.1.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file openframe_adapters_db_redis-1.1.0.tar.gz.

File metadata

File hashes

Hashes for openframe_adapters_db_redis-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6f544ba61d48e3f9509b4d1410946ba8e00e8c2f83937e9b3a1230a02225680f
MD5 0fa8fd1eda355aed0bee1304b6a27661
BLAKE2b-256 899d4f78f26ec6eae9da9000d0e028f94d80c42894ca84937a5edf3c045c3cee

See more details on using hashes here.

File details

Details for the file openframe_adapters_db_redis-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openframe_adapters_db_redis-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b01770edb7f3929fbff2cb683a629635fd2db3cfd88549d914234ef4e3a1378d
MD5 dfec9f10b2dfbc0e9152f87443443cd0
BLAKE2b-256 590877ae80cf047c78adcb8a835fd43cbbec5e958684a8a2a35c7788ef5d2db0

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