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

# 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

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: redis-client-1.0.1.tar.gz
  • Upload date:
  • Size: 3.8 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-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7b30c18789ba226541f950d70df0e05008d1c407a8f47502742c7cf4ec99b7f1
MD5 36b51ade7efac1c74ddf049a9f88974a
BLAKE2b-256 98ac3ccbc162684b2293ba81348c59d940ee0661d3e11c0ed7288426f177e3e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: redis_client-1.0.1-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-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 53dc028fd1f146d85435bf720057772282a58041bae47e5e47cb30e653cdcf1c
MD5 74d816ddf55152695a944a9bf5db0622
BLAKE2b-256 0564f57ac30199323298724fba5ad6f7b3a8eb07bfb8f2296b287ae2b0249a58

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