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,可用于设置连接池大小、超时、
响应解码等选项:
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,
},
)
使用
初始化
from flask_redis_cache import FlaskRedisCache
cache = FlaskRedisCache()
cache.init_app(app)
扩展会为每个 Flask app 创建一个共享的 redis-py client。连接会在请求之间通过 连接池复用,不需要在请求结束时手动关闭。
redis client的使用方法
cache.redis.set("key", "value")
Metadata
Release files for flask-redis-cache 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flask_redis_cache-0.1.3.tar.gz | 2.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flask_redis_cache-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.8 kB
Release files / flask_redis_cache-0.1.3.tar.gz
| Download URL | flask_redis_cache-0.1.3.tar.gz |
|---|---|
| Size | 2.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7bbc40af4715aa0e128bb11c5d1f9bf0221bb6f1f473046deaafc1e57c06319
|
|
BLAKE2b-256 checksum How to use checksums |
6782d1d07bc1a914cf0b5dd10066bc63e9146cae9cdd7c910520413b2a91cd2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Linux/6.8.0-134-generic
|
Release files / flask_redis_cache-0.1.3-py3-none-any.whl
| Download URL | flask_redis_cache-0.1.3-py3-none-any.whl |
|---|---|
| Size | 3.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce42fe6daf22e69f760df089cdd180aa6727b3f3320ba39ac10867b8fc999084
|
|
BLAKE2b-256 checksum How to use checksums |
0f7bb2fd0ed56ccf338bbad4222c2cb0189f57128af5437e0522e105d9b1918c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Linux/6.8.0-134-generic
|