A simple client for Redis
Project description
Redis client
Simple Redis client for python.
It has been made to simplify working with Redis in python.
Usage
Instantiate Cache()
, give the Redis host
, port
and db
.
Then you can get a cached entry with Cache.get_data_from_cache()
and add an entry to Redis with Cache.save_data_to_cache()
⚠️The data send to cache NEEDS TO BE A DICTIONARY! ⚠️
Code example
from redis_client.client import Cache
from time import sleep
from tpying import Dict
cache = Cache(redis_host="localhost", redis_port=6379, redis_db=0, log_level="INFO")
def username_expander(username: str) -> Dict[str, str]:
"""Example of a function that require caching."""
# Key that will be use to retrieve cached data
# Note that I include the parameter 'username' in the key to make sure we only cache unique value.
key = f"username_expander:{username}"
# Check if the data is already caches
cached_data = cache.get_data_from_cache(key)
# Return it if yes
if cached_data:
return cached_data
sleep(10)
data = {"expanded_username": f"{username}_123"}
# Save data to cache with an expiration time of 12 hours
cache.save_data_to_cache(key, data, expiration_in_hours=12)
return data
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
redis-client-1.0.0.tar.gz
(3.7 kB
view details)
Built Distribution
File details
Details for the file redis-client-1.0.0.tar.gz
.
File metadata
- Download URL: redis-client-1.0.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0 CPython/3.10.5 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a6a75e1298815cadff7d5cf4c4959c9a9ac5a7e21b9defe75efea9efdd345f0 |
|
MD5 | d87bb5f7178f9d0a3c0e5e5813e747c1 |
|
BLAKE2b-256 | 29f30a2f869bdb90500ba4de054716c8ad926bb3f845582d910938c2561d769a |
File details
Details for the file redis_client-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: redis_client-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0 CPython/3.10.5 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f7fce685625de7a3ffa903bc2cabb5afc4ad2a9fec03db0ef7a73ef16245e92 |
|
MD5 | 45b4664eef1f45389b888f72025dd273 |
|
BLAKE2b-256 | 91bc8ab8c120ee44dc8281f55d9786ff703af6a64f7d46a066072ed984d917e7 |