콘텐츠로 이동

spakky-redis

Redis 캐시 백엔드 플러그인입니다.

Redis 캐시

Redis implementation of the spakky-cache contract.

ISyncRedisClient

Bases: ABC

Explicit sync Redis boundary used by RedisCache.

IAsyncRedisClient

Bases: ABC

Explicit async Redis boundary used by RedisCache.

IRawSyncRedisClient

Bases: ABC

Explicit raw sync Redis boundary before response narrowing.

IRawAsyncRedisClient

Bases: ABC

Explicit raw async Redis boundary before response narrowing.

RedisRawSyncClient(raw)

Bases: IRawSyncRedisClient

Raw sync Redis client wrapper for redis-py.

Source code in plugins/spakky-redis/src/spakky/plugins/redis/cache.py
def __init__(self, raw: Redis) -> None:
    self._raw = raw

RedisRawAsyncClient(raw)

Bases: IRawAsyncRedisClient

Raw async Redis client wrapper for redis-py.

Source code in plugins/spakky-redis/src/spakky/plugins/redis/cache.py
def __init__(self, raw: AsyncRedis) -> None:
    self._raw = raw

SyncRedisAdapter(raw)

Bases: ISyncRedisClient

Typed boundary over the redis-py sync client.

Source code in plugins/spakky-redis/src/spakky/plugins/redis/cache.py
def __init__(self, raw: IRawSyncRedisClient) -> None:
    self._raw = raw

AsyncRedisAdapter(raw)

Bases: IAsyncRedisClient

Typed boundary over the redis-py async client.

Source code in plugins/spakky-redis/src/spakky/plugins/redis/cache.py
def __init__(self, raw: IRawAsyncRedisClient) -> None:
    self._raw = raw

RedisCache(config=None, *, client=None, async_client=None)

Bases: ITaggedCache[T], IStampedeProtectedCache[T], ICacheMetrics[T], IWritePolicyCache[T]

Redis-backed cache that stores pickled values under a configured prefix.

Source code in plugins/spakky-redis/src/spakky/plugins/redis/cache.py
def __init__(
    self,
    config: RedisCacheConfig | None = None,
    *,
    client: ISyncRedisClient | None = None,
    async_client: IAsyncRedisClient | None = None,
) -> None:
    self._config = config or RedisCacheConfig()
    self._client = client or self._create_client()
    self._async_client = async_client or self._create_async_client()
    self._hits = 0
    self._misses = 0
    self._writes = 0
    self._deletes = 0
    self._clears = 0
    self._tag_evictions = 0
    self._stampede_waits = 0
    self._ping()

ping()

Validate that the configured Redis backend is reachable.

Source code in plugins/spakky-redis/src/spakky/plugins/redis/cache.py
def ping(self) -> None:
    """Validate that the configured Redis backend is reachable."""
    self._ping()

Actuator 확장

Actuator extensions for the Redis cache backend.

RedisCacheHealthProbe(cache, config)

Bases: AbstractHealthProbe

Report Redis cache backend reachability.

Source code in plugins/spakky-redis/src/spakky/plugins/redis/actuator.py
def __init__(self, cache: RedisCache[object], config: RedisCacheConfig) -> None:
    self._cache = cache
    self._config = config

RedisCacheMetricsInfoContributor(cache)

Bases: IInfoContributor

Expose Redis cache metrics through actuator info.

Source code in plugins/spakky-redis/src/spakky/plugins/redis/actuator.py
def __init__(self, cache: RedisCache[object]) -> None:
    self._cache = cache

설정

Redis cache backend configuration.

RedisCacheConfig()

Bases: BaseSettings

Redis cache backend configuration loaded from environment variables.

Source code in plugins/spakky-redis/src/spakky/plugins/redis/common/config.py
def __init__(self) -> None:
    super().__init__()

host = 'localhost' class-attribute instance-attribute

Redis server hostname.

port = 6379 class-attribute instance-attribute

Redis server port.

db = 0 class-attribute instance-attribute

Redis database index.

username = None class-attribute instance-attribute

Optional Redis ACL username.

password = None class-attribute instance-attribute

Optional Redis password.

use_ssl = False class-attribute instance-attribute

Use redis+ssl transport when true.

key_prefix = 'spakky:cache:' class-attribute instance-attribute

Prefix applied to keys managed by this cache backend.

socket_timeout = 5.0 class-attribute instance-attribute

Socket timeout in seconds for Redis operations.

scheme property

Return the Redis URL scheme for this configuration.

connection_url property

Return a Redis connection URL without embedding credentials.

플러그인 진입점

Plugin initialization for Redis cache integration.

initialize(app)

Register Redis cache configuration and backend pods.

Source code in plugins/spakky-redis/src/spakky/plugins/redis/main.py
def initialize(app: SpakkyApplication) -> None:
    """Register Redis cache configuration and backend pods."""
    app.add(RedisCacheConfig)
    app.add(RedisCache)
    app.add(redis_cache_health_probe)
    app.add(redis_cache_metrics_info_contributor)

redis_cache_health_probe(cache, config)

Create the Redis cache actuator health probe.

Source code in plugins/spakky-redis/src/spakky/plugins/redis/main.py
@Pod()
def redis_cache_health_probe(
    cache: RedisCache[object],
    config: RedisCacheConfig,
) -> RedisCacheHealthProbe:
    """Create the Redis cache actuator health probe."""
    return RedisCacheHealthProbe(cache, config)

redis_cache_metrics_info_contributor(cache)

Create the Redis cache actuator metrics info contributor.

Source code in plugins/spakky-redis/src/spakky/plugins/redis/main.py
@Pod()
def redis_cache_metrics_info_contributor(
    cache: RedisCache[object],
) -> RedisCacheMetricsInfoContributor:
    """Create the Redis cache actuator metrics info contributor."""
    return RedisCacheMetricsInfoContributor(cache)

에러

Error classes for the spakky-redis package.

AbstractSpakkyRedisError

Bases: AbstractSpakkyCacheError, ABC

Base class for Redis cache backend errors.

RedisCacheOperationError

Bases: AbstractSpakkyRedisError

Raised when a Redis operation fails.

RedisCacheSerializationError

Bases: AbstractSpakkyRedisError

Raised when a cache value cannot be serialized or deserialized.

RedisCacheLockTimeoutError

Bases: AbstractSpakkyRedisError

Raised when a cache population lock cannot be acquired in time.