Skip to main content

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_HOSTREDIS_PORTREDIS_DBREDIS_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")

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_redis_cache-0.1.3.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

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

flask_redis_cache-0.1.3-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file flask_redis_cache-0.1.3.tar.gz.

File metadata

  • Download URL: flask_redis_cache-0.1.3.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.8.0-134-generic

File hashes

Hashes for flask_redis_cache-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f7bbc40af4715aa0e128bb11c5d1f9bf0221bb6f1f473046deaafc1e57c06319
MD5 a81679424453decc829d62bdf380a310
BLAKE2b-256 6782d1d07bc1a914cf0b5dd10066bc63e9146cae9cdd7c910520413b2a91cd2c

See more details on using hashes here.

File details

Details for the file flask_redis_cache-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: flask_redis_cache-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.8.0-134-generic

File hashes

Hashes for flask_redis_cache-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ce42fe6daf22e69f760df089cdd180aa6727b3f3320ba39ac10867b8fc999084
MD5 6e06fce6f80e00b354981d0011f3638f
BLAKE2b-256 0f7bb2fd0ed56ccf338bbad4222c2cb0189f57128af5437e0522e105d9b1918c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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