Skip to main content

Quick start

Install

pip install redis_decorator

Initialize

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

Examples

Make sure you have redis up and running.(https://redis.io/)

Example1 : Cache string return

from time import sleep
from datetime import datetime
@cache.ttl(300)
def pseudo_calc():
    sleep(1)
    print("Computation in progress")
    return str(datetime.now())

for i in range(10):
    print(pseudo_calc())

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
@cache.df(300)
def return_a_df(*args, **kwargs):
    sleep(1)
    print("Computation in progress")
    return pd.DataFrame({"time": [str(datetime.now()) for _ in range(5)], "foo": list(range(5))})


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

Example 3: Cache dict

@cache.dict(60)
def return_a_dict(*args, **kwargs):
    sleep(1)
    print("Computation in progress")
    return {"now": str(datetime.now())}


for i in range(5):
    print(return_a_dict())

Example 4: Cache float number

@cache.float(60)
def return_a_float(*args, **kwargs):
    return random()


for i in range(5):
    print(return_a_float())

Delete Cache

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

Release files for redis-decorator 0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for redis-decorator 0.4
File Size Uploaded
redis_decorator-0.4.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for redis-decorator 0.4
File Interpreter ABI Platform
redis_decorator-0.4-py3-none-any.whl Python 3 none any Details

Total release size: 7.7 kB

Release files / redis_decorator-0.4.tar.gz

Download URL redis_decorator-0.4.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2a9dd3c131b45eb4a9e53813f8a0d2bb55420191c23dee4572b676e28f670fa5
BLAKE2b-256 checksum
How to use checksums
14206c916232c4fea1aaa6a993510e724d01f552ef806ef4ed43ecc98207c503
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

Release files / redis_decorator-0.4-py3-none-any.whl

Download URL redis_decorator-0.4-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61c11b8cd6fb72caedd26da28830688e77667c9f5abac00c5279a76ba56777b2
BLAKE2b-256 checksum
How to use checksums
3d69c3b9890f032fd059a80508b2e62020c39ee01616491ee3722f1591e53fc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.4 This release

2 release files

0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page