Metadata-Version: 2.1
Name: red-cache
Version: 0.0.4
Summary: UNKNOWN
Home-page: http://vvia.xyz/wjLSh5
Author: Memory_Leak
Author-email: irealing@163.com
License: UNKNOWN
Platform: UNKNOWN
Requires-Dist: redis (>=3.0.1)

# red_cache

#### 介绍
基于Redis实现的Python缓存工具
#### 示例
##### 安装方法
```shell
$ pip install red-cache==0.0.4
```

##### 缓存函数执行结果

```python
@redis_cache.pickle_cache(key=lambda v, t: "cache:{}:{}".format(v, t), ex=180)
def hell_world(val: str, times: int):
    return val * times
```
##### 保存JSON缓存数据

```python

@redis_cache.json_cache(key=lambda v, t: "cache:{}:{}".format(v, t), ex=180)
def hell_world(val: str, times: int):
    return {"val": val, "times": times}

```

##### 缓存的属性

```python
class Demo:
    def load_xxx(self):
        return

    xxx = redis_cache.property(key=lambda: "Demo::xxx", ex=10)(lambda self: self.load_xxx())

```
#### 删除缓存

```python

@redis_cache.remove(lambda o: "auth::user:{}".format(o))
def modify_user(user_id):
    # DO MODIFY USER
    pass

```
使用返回值

```python

@redis_cache.remove(lambda o: "auth::user:{}".format(o), by_return=True)
def modify_user(user_id):
    # DO MODIFY USER
    return "*********"
```
使用生成器

```python
@redis_cache.remove(lambda o: "auth::user:{}".format(o), by_return=True)
def modify_users(users):
    # modify users
    for u in users:
        yield u

```

@author:[Memory_Leak](http://vvia.xyz/wjLSh5)

