Skip to main content

Using redis as external redis_dec by one line of code

Project description

Quick start


pip install redis_decorator


from redis_dec import Cache
from redis import StrictRedis
redis = StrictRedis(decode_responses=True)
cache = Cache(redis)


Make sure you have redis up and running.(

Example1 : Cache string return

from time import sleep
from datetime import datetime
def pseudo_calc():
    print("Computation in progress")
    return str(

for i in range(10):

Example 2: Cache Pandas Dataframe

# Set cache's time to live to 300 seconds (expires in 300 seconds)
# If left blank, e.g. @cache.df(), cache will stay forever. Don't recommended.
import pandas as pd
def return_a_df(*args, **kwargs):
    print("Computation in progress")
    return pd.DataFrame({"time": [str( for _ in range(5)], "foo": list(range(5))})

for i in range(5):
    print(return_a_df(1, 5))

Example 3: Cache dict

def return_a_dict(*args, **kwargs):
    print("Computation in progress")
    return {"now": str(}

for i in range(5):

Example 4: Cache float number

def return_a_float(*args, **kwargs):
    return random()

for i in range(5):

Delete Cache

# Delete cache by function and signature
cache.delete_cache(return_a_float, 2, b=3) 
# Delete cache by function
# Delete all caches

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
redis_decorator-0.4-py3-none-any.whl (4.2 kB) Copy SHA256 hash SHA256 Wheel py3
redis_decorator-0.4.tar.gz (3.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page