Skip to main content

A library that simplifies working with Redis in Python

Project description

simple-redis-cache

Coverage PyPI version

Простой декоратор для кэширования асинхронных функций в Redis.

Особенности

  • Автоматическая генерация ключей — ключи создаются на основе имени функции и аргументов
  • Инвалидация по префиксу — очищайте кэш группами
  • Кастомный JSON-энкодер — поддерживает datetime, Decimal, UUID, Pydantic-модели
  • Устойчивость к ошибкам — ошибки Redis не ломают приложение
  • Гибкая настройка — можно передать свой логгер

Установка

pip install simple-redis-cache

Пример

from redis.asyncio import Redis
from simple_redis_cache import Cache

redis = Redis()
cache = Cache(redis)

@cache.cache(ttl=60, prefix="user")
async def get_user(user_id: int):
    return {"id": user_id, "name": "Alice"}

# Первый вызов — вычисляется, второй — из кэша
r1 = await get_user(1)
r2 = await get_user(1)

# Одинаковый результат
print(r1 == r2)

Инвалидация

await cache.invalidate_cache(prefix="user")

Лицензия

MIT

Автор

hotpotato89

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

simple_redis_cache-0.2.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

simple_redis_cache-0.2.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file simple_redis_cache-0.2.0.tar.gz.

File metadata

  • Download URL: simple_redis_cache-0.2.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"EndeavourOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for simple_redis_cache-0.2.0.tar.gz
Algorithm Hash digest
SHA256 de4cced6ac9d18b2967987182141a02fed2403780c630d4854bfff1df6e5e4cb
MD5 939e541b561c1c2a760d305e03ec196d
BLAKE2b-256 b8c7d8b7cfbfe849348ff5182536d50b5f1692616cc321e4d2494b5258ae2f38

See more details on using hashes here.

File details

Details for the file simple_redis_cache-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: simple_redis_cache-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"EndeavourOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for simple_redis_cache-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1da91a983e7462a0cc4fedbc06dfd0a084c8bc961d9054a0b29333885379d36
MD5 721eb91ad0c55407e09e1f26813f79c3
BLAKE2b-256 198a2f89baeb195391996920ec13333e0c8da80d4c36e9227c0ea7f95ef0f48f

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