Skip to main content

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-0.3.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

redis_client-0.3.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file redis-client-0.3.0.tar.gz.

File metadata

  • Download URL: redis-client-0.3.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

Hashes for redis-client-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b697d2febf5cf9047a59947e1edc3b12e1d17ac7d31bf8ca5582f22e7314d7ab
MD5 694f7b3784ffa8e12c1814217e860fe3
BLAKE2b-256 a87a1844ef93689a8969d025b7311cbee71f75441760e9ad88512b1b71a5499b

See more details on using hashes here.

File details

Details for the file redis_client-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: redis_client-0.3.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

Hashes for redis_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36954201b41e5310dfb3e63cb39281625fcf9b546113df6a099a17bd9f1575ac
MD5 1329f4f21a4e67bad8183b04294fff8e
BLAKE2b-256 a344b42707fc398ff0bdac70b6ae0cd1be60789624188bc2ec1b1a94065eb19c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page