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.3.1.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.3.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spakky_redis-6.3.1.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.3.1.tar.gz
Algorithm Hash digest
SHA256 7d11c6d373e13dc70ea6ec53bbaa29e4e7ba1736041439a37a388127b6e03795
MD5 95b3711574061e360a5496c7d50c4e4a
BLAKE2b-256 b7fe474212cc4ec67f62b2bdd8047161c6338d902a320403618ebebdb64b0210

See more details on using hashes here.

Provenance

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

Publisher: publish-package.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.3.1-py3-none-any.whl.

File metadata

  • Download URL: spakky_redis-6.3.1-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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6555c71bd89674d85146a997246925e7cca78f9c7ecfabfc49ccc2b6400d72d1
MD5 a4cd8e97478e8d96d8138e5ff3771d0d
BLAKE2b-256 991d481d5d9cb67e747497bd1a08019d6d1bd1972c93a468411eb1e7e89b03ac

See more details on using hashes here.

Provenance

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

Publisher: publish-package.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