Skip to main content

Class and decorator to use with Redis

Project description

Redis Decorator Generator

Deploy Workflow

CI Workflow

Description

This package is a simple wrapper around the standard redis.Redis package pip install redis.

The 'generate' function is meant to help speed up the integration process.

Purpose

I personally like using decorators for caching. This allows for quick add/remove caching of a function.

redis_decorator_generator.generate is a quick way to point to a custom (Redis server)[https://redis.io/].

Examples

Example 1

Use the generator directly on a function.

    @generate(redis_url="redis://:foobared@localhost:6379/0")(ttl=60)
    def my_func(*args: Any, **kwargs: Any) -> Any:
        sarg = ":".join([str(arg) for arg in args])
        skwarg = ":".join([f"{key}={str(value)}" for key, value in kwargs.items()])
        return sarg + "::" + skwarg

Example 2

Generate the decorator so that it can be imported.

    cache = generate(redis_url="redis://:foobared@localhost:6379/0")

    @cache(ttl=60)
    def my_func(*args: Any, **kwargs: Any) -> Any:
        sarg = ":".join([str(arg) for arg in args])
        skwarg = ":".join([f"{key}={str(value)}" for key, value in kwargs.items()])
        return sarg + "::" + skwarg

Example 3

With attempting to test, I came across the fakeredis package. This package returns a connection to the fake Redis server, which can then be passed into generate as redis_client key word argument. This allows to initialize the RedisCache.from_pool() to be able directly interact with the fake Redis instance setup for unit testing.

Example Code Found Here

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_decorator_generator-0.0.4.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redis_decorator_generator-0.0.4-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file redis_decorator_generator-0.0.4.tar.gz.

File metadata

File hashes

Hashes for redis_decorator_generator-0.0.4.tar.gz
Algorithm Hash digest
SHA256 62b1cab33f2bb2f0e48817aedc7ce4e7fb515aed86b9dbc261c17302fc5ae60d
MD5 3aa83ef9ca137ce884abc22dfd36f17f
BLAKE2b-256 6d3fae12148c3161670d903fe7f426b14a1988174e232f858e65e3c83f45877a

See more details on using hashes here.

Provenance

The following attestation bundles were made for redis_decorator_generator-0.0.4.tar.gz:

Publisher: deploy.yaml on bkmetzler/redis-decorator-generator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redis_decorator_generator-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for redis_decorator_generator-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5223031d5332f7b4325fb326cee6a953732b16ac6806464ff63b9bb72eff50aa
MD5 d928e17154ec3b4e3b3c8a90e80abc63
BLAKE2b-256 ed906e49845ef13926385c0de8a9249d683084b47909776122d07e26de9dc8eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for redis_decorator_generator-0.0.4-py3-none-any.whl:

Publisher: deploy.yaml on bkmetzler/redis-decorator-generator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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