Metadata-Version: 2.3
Name: flask-redis-cache
Version: 0.1.3
Summary: 
Author: codeif
Author-email: me@codeif.com
Requires-Python: >=3.10
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: flask (>=1)
Requires-Dist: redis[hiredis] (>=6.0)
Description-Content-Type: text/markdown

# flask-redis-cache

```
pip install flask-redis-cache
```

## 设置项

| 配置项 | 默认值 | 说明 |
| :--- | :--- | :--- |
| `REDIS_HOST` | `127.0.0.1` | Redis 服务器地址 |
| `REDIS_PORT` | `6379` | Redis 服务器端口 |
| `REDIS_DB` | `1` | Redis 数据库编号 |
| `REDIS_URL` | 未设置 | Redis 连接 URL；设置后优先于以上三个连接配置 |
| `REDIS_CLIENT_KWARGS` | `{}` | 传递给 redis-py client 的其他参数 |

设置了 `REDIS_URL` 时，它优先于 `REDIS_HOST`、`REDIS_PORT` 和 `REDIS_DB`。
`REDIS_CLIENT_KWARGS` 会直接传给 redis-py，可用于设置连接池大小、超时、
响应解码等选项：

```python
app.config.update(
    REDIS_URL="redis://localhost:6379/1",
    REDIS_CLIENT_KWARGS={
        "max_connections": 50,
        "socket_connect_timeout": 2,
        "socket_timeout": 2,
        "decode_responses": True,
    },
)
```

## 使用


### 初始化

```python
from flask_redis_cache import FlaskRedisCache

cache = FlaskRedisCache()
```

```python
cache.init_app(app)
```

扩展会为每个 Flask app 创建一个共享的 redis-py client。连接会在请求之间通过
连接池复用，不需要在请求结束时手动关闭。

### redis client的使用方法

```python
cache.redis.set("key", "value")
```

