Skip to main content

A library that simplifies working with Redis in Python

Project description

simple-redis-cache

PyPI Redis uv Pytest

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

  1. Документация
  2. Ссылка на PyPI

Особенности

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

Установка

pip install simple-redis-cache

Использование:

from simple_redis_cache.sync import Cache  # Синхронный
from simple_redis_cache.asyncio import 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-1.0.1.tar.gz (7.8 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-1.0.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_redis_cache-1.0.1.tar.gz
  • Upload date:
  • Size: 7.8 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-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4dec9bbfbf022d152e56b3c2c4cad5e88191f6a2115f554044a79413248633a3
MD5 339b82557d8511334bcab97b21ab41c3
BLAKE2b-256 20c9f33483198e68ba836b8dece72182d3d7f8cfac4c7541faa34fcbe1e254b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simple_redis_cache-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 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-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2dc9b038e92dd89fbacdb3274c81a609c6f24930f041da2c709cb5b1d4621773
MD5 22bfe3408efeb4d5e31cfa1b354752ce
BLAKE2b-256 1921fb98ca2af81c8abd0111c6aeb8c0a4759e3c7ce2005c8cde087db801b29f

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