Skip to main content

Redis cache backend plugin for Spakky Framework

Project description

Spakky Redis

Redis cache backend plugin for Spakky Framework.

Installation

pip install spakky-redis

Features

  • Shared cache backend: RedisCache[T] stores values in Redis so multiple process instances can observe the same entries.
  • Core contract compatibility: Implements spakky-cache sync and async ICache[T] paths.
  • TTL semantics: Positive TTL values are translated into Redis millisecond expiry; missing and expired keys return CacheMiss.
  • Loud failures: Redis connection/configuration failures and serialization failures are raised as Spakky cache errors.
  • Scoped clear: clear removes keys under the configured prefix instead of flushing the Redis database.

Quick Start

from datetime import timedelta

from spakky.cache import CacheHit
from spakky.plugins.redis import RedisCache

cache = RedisCache[str]()
cache.set("profile:42", "Ada", ttl=timedelta(minutes=5))

result = cache.get("profile:42")
if isinstance(result, CacheHit):
    print(result.value)

Configuration

RedisCacheConfig follows the standard Spakky @Configuration pattern and reads environment variables with the SPAKKY_REDIS__ prefix.

Environment variable Default
SPAKKY_REDIS__HOST localhost
SPAKKY_REDIS__PORT 6379
SPAKKY_REDIS__DB 0
SPAKKY_REDIS__USERNAME unset
SPAKKY_REDIS__PASSWORD unset
SPAKKY_REDIS__USE_SSL false
SPAKKY_REDIS__KEY_PREFIX spakky:cache:
SPAKKY_REDIS__SOCKET_TIMEOUT 5.0

Async Usage

from spakky.cache import CacheHit
from spakky.plugins.redis import RedisCache

cache = RedisCache[int]()
await cache.set_async("answer", 42)

result = await cache.get_async("answer")
if isinstance(result, CacheHit):
    assert result.value == 42

Contract Notes

RedisCache is a backend implementation of the spakky-cache application data cache contract. Business code should depend on ICache[T] and can switch between InMemoryCache and RedisCache without changing cache hit/miss handling.

Values are serialized with pickle and stored under SPAKKY_REDIS__KEY_PREFIX. clear() and clear_async() delete only keys under that prefix. Redis failures, unexpected response types, and serialization failures are raised as Spakky cache errors instead of being treated as cache misses.

This plugin does not add distributed locks, cache stampede protection, tag invalidation, write-through/write-behind policies, or metrics exporters.

License

MIT License

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

spakky_redis-6.4.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

spakky_redis-6.4.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file spakky_redis-6.4.0.tar.gz.

File metadata

  • Download URL: spakky_redis-6.4.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spakky_redis-6.4.0.tar.gz
Algorithm Hash digest
SHA256 534e59b68cd023f0ae527bdb8d27bc4f260e546f3571430c5a1e89d4dbcd74a8
MD5 423ec861fbe3affd81a8d28812220855
BLAKE2b-256 aa3e2ceb0a8604f1b714b9dc171fe83fe903e67995889c262cda523a8630c41d

See more details on using hashes here.

Provenance

The following attestation bundles were made for spakky_redis-6.4.0.tar.gz:

Publisher: release.yml on E5presso/spakky-framework

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spakky_redis-6.4.0-py3-none-any.whl.

File metadata

  • Download URL: spakky_redis-6.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spakky_redis-6.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eff1c3d722739a503f58731824d1606a5bef52b8b52ef57d5876aacfd35a7a55
MD5 7f214985bcc150e6b328c559bd9e34ff
BLAKE2b-256 1ad08a4b1bb340d3ef44cf0a0d689f7c3d43b9a93874445c9835fc262ca6cb6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for spakky_redis-6.4.0-py3-none-any.whl:

Publisher: release.yml on E5presso/spakky-framework

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