Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/graphtylove/redis_client_python
Simple Redis client for python
https://github.com/graphtylove/redis_client_python
cache caching client package python python-package python3 redis
Last synced: 21 days ago
JSON representation
Simple Redis client for python
- Host: GitHub
- URL: https://github.com/graphtylove/redis_client_python
- Owner: GraphtyLove
- Created: 2022-09-05T09:43:53.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-05T11:26:04.000Z (over 2 years ago)
- Last Synced: 2025-01-20T21:58:41.079Z (25 days ago)
- Topics: cache, caching, client, package, python, python-package, python3, redis
- Language: Python
- Homepage: https://pypi.org/project/redis-client/
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```python
from redis_client.client import Cache
from time import sleep
from tpying import Dict# Redis Configuration
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
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
```