Skip to main content

This project/library contains common elements related to Redis integration...

Project description

core-redis

This project/library contains common elements related to Redis integration.


Python Versions License Pipeline Status Docs Status Security

Installation

pip install core-redis
uv pip install core-redis  # or using UV

Features

  • RedisClient: thin connection wrapper that decouples the ecosystem from the underlying redis library.

  • cache_redis_based: write-through caching decorator backed by Redis (L2) with an in-memory LRU as L1.

RedisClient

RedisClient abstracts the redis library so the rest of the ecosystem never imports it directly. The connection is created lazily on first use and is thread-safe.

from core_redis import RedisClient

client = RedisClient(host="localhost", port=6379, db=0)

client.set("key", b"value", ex=60)        # store with 60 s TTL
data  = client.get("key")                 # b"value" or None
count = client.delete("key")              # 1
n     = client.exists("key", "other")     # 0–N
alive = client.ping()                     # True

Additional keyword arguments are forwarded verbatim to redis.Redis (e.g. ssl=True, socket_timeout=5).

cache_redis_based

Write-through caching decorator: L1 is a bounded in-memory LRU; L2 is Redis. TTL is handled natively by Redis (SET … EX), so no background threads or manual expiry are needed.

from core_redis.decorators import cache_redis_based

@cache_redis_based(
    key_prefix="myapp/",
    ttl=3600,
    redis_kwargs={"host": "localhost", "port": 6379},
)
def fetch_reference_data(dataset: str) -> dict:
    ...

Local Redis with Docker

Start a Redis server on the default port:

docker run -d --name redis-local -p 6379:6379 redis:latest

Stop and remove it when done:

docker stop redis-local && docker rm redis-local

Setting Up for Development

pip install --upgrade pip
pip install virtualenv
virtualenv --python=python3.12 .venv
source .venv/bin/activate
pip install -e ".[dev]"

Running Tests

python manager.py run-tests                                          # unit tests
python manager.py run-tests --test-type integration
python manager.py run-coverage                                       # unit + coverage

Functional tests require a running Redis server (see Local Redis with Docker):

# defaults: REDIS_HOST=localhost REDIS_PORT=6379 REDIS_DB=15
python manager.py run-tests --test-type functional --pattern "*.py"

Contributing

Contributions are welcome! Please:

  1. Fork the repository

  2. Create a feature branch

  3. Write tests for new functionality

  4. Ensure all tests pass: python manager.py run-tests

  5. Run linting: pylint core_redis

  6. Run security checks: bandit -r core_redis

  7. Submit a pull request

License

This project is licensed under the MIT License. See the LICENSE file for details.

Support

For questions or support, please open an issue on GitLab or contact the maintainers.

Authors

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

core_redis-1.0.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

core_redis-1.0.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file core_redis-1.0.0.tar.gz.

File metadata

  • Download URL: core_redis-1.0.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for core_redis-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c439a614647ab38ae6a3ae83f9ed195b1edbf9e46cca53a496b2699e279456cb
MD5 5edd9f879daa83f76a9163f3bf20e733
BLAKE2b-256 f96f7a692793c36a170a1a5fedf3eee766531d8a16a063db46d0a484e7b49ad3

See more details on using hashes here.

File details

Details for the file core_redis-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: core_redis-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for core_redis-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83fd2fd833de7cad065787793ede17ae6cfda141f2ce0079e1e5b44569c981c1
MD5 95eb47566d17d61c599cee7fb5ae0c23
BLAKE2b-256 90100039acd54752109c1bc72bba0abc56c1ac1863b0d3f46a755262afe1a8b6

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