Metadata-Version: 2.4
Name: redis-decorator-generator
Version: 0.0.4
Summary: Class and decorator to use with Redis
Project-URL: Homepage, https://github.com/bkmetzler/redis-decorator-generator
Project-URL: Issues, https://github.com/bkmetzler/redis-decorator-generator/issues
Author-email: Brian Metzler <baldie@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Brian Metzler
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE.md
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.12
Requires-Dist: redis
Description-Content-Type: text/markdown

# Redis Decorator Generator

[![Deploy Workflow](https://github.com/bkmetzler/redis-decorator-generator/actions/workflows/deploy.yaml/badge.svg?branch=main)](https://github.com/bkmetzler/redis-decorator-generator/actions/workflows/deploy.yaml)

[![CI Workflow](https://github.com/bkmetzler/redis-decorator-generator/actions/workflows/pull_request.yaml/badge.svg?branch=main)](https://github.com/bkmetzler/redis-decorator-generator/actions/workflows/pull_request.yaml)

## 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.

```python
    @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](https://github.com/bkmetzler/redis-decorator-generator/blob/main/tests/test_redis_client.py#L7-L20)
