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

Uploaded Source

Built Distribution

redis_client-0.2.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: redis-client-0.2.0.tar.gz
  • Upload date:
  • Size: 3.6 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.2.0.tar.gz
Algorithm Hash digest
SHA256 3106bdc31f64364bc52e74670e0a874f9efbde9da5a0914f4a7894658b450ff3
MD5 8c55a567d95d2176c5c825d127679059
BLAKE2b-256 d8d0753b3a88c0d2056185a31a066d42a666383e17acfdb4853a82e7aa2d36ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: redis_client-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 adf7dee90f83fbe8c06f002ac58a52b2cb1f5266ac1105775a7d886abaa86b04
MD5 264a02dbcf4e6e896c32403205e38ef7
BLAKE2b-256 dc5990b606b74c99c722d2c23c727b5933196d0c27c4c4e819a55f6aeb05a905

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