Dynamic Config
基于Redis Cluster的动态配置管理系统,采用主动拉取(Pull)+推送(Push)双模式更新策略,内置LRU本地缓存。
核心特性
- 双模式更新:主动拉取(过期/缓存未命中) + 推送订阅(实时变更)
- 高效缓存:LRU本地缓存,支持容量和过期时间配置
- 集群支持:原生支持Redis Cluster分布式部署
- 高可用:订阅模式自动重连机制
架构设计
Installation
pip install dynamic-config
快速开始
客户端
from dynamic_config_qq import DynamicConfigClient
# 初始化客户端
client = DynamicConfigClient(
cluster_nodes=[{'host': 'redis', 'port': 6301, 'name': 'paas.dc.node1.dzqd.cn:6301'}, ],
password='pwd',
cache_capacity=1000, # LRU缓存容量
cache_expire=300, # 缓存过期时间(秒)
enable_subscription=True # 启用订阅接受推送
)
# 读写配置
client.set("timeout", 30) # 写入配置
timeout = client.get("timeout") # 读取配置
管理接口
from dynamic_config_qq import DynamicConfigManager
config_manager = DynamicConfigManager(
cluster_nodes=[{'host': 'redis', 'port': 6301, 'name': 'paas.dc.node1.dzqd.cn:6301'}],
password='pwd',
socket_timeout=10,
socket_connect_timeout=30,
)
config_manager.create_config("test_key3", "test_value")
config_manager.update_config("test_key3", "updated_value")
config_manager.delete_config("test_key3")
配置
Client配置参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
cluster_nodes |
List[str] | 必填 | Redis Cluster节点列表 (如 =[{'host': 'redis', 'port': 6301, 'name': 'paas.dc.node1.dzqd.cn:6301'}]) |
password |
str | None | Redis访问密码 |
cache_capacity |
int | 1000 | LRU缓存最大容量,0表示不启用本地缓存 |
cache_expire |
int | 300 | 缓存过期时间(秒) |
socket_timeout |
int | 10 | Redis操作超时时间(秒) |
socket_connect_timeout |
int | 30 | Redis连接超时时间(秒) |
enable_subscription |
bool | False | 启用订阅,接收push消息 |
subscription_reconnection_interval |
int | 5 | 订阅断开后重连间隔(秒) |
channel |
str | "global" | 配置变更通知频道前缀 |
使用建议
- 高频读、低频写:
- 增大cache_expire减少Redis访问;
- 关闭订阅或增加订阅断开重连时间间隔,避免长链接占用或频繁建立连接。
- 低频读、对配置更新时效敏感:关闭cache,每次读取都从Redis获取。
- 配置立即生效:重启服务(不建议使用接受push消息的订阅模式,仅在服务不支持重启更新配置的情况下使用)。
Metadata
Release files for dynamic-config-qq 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dynamic_config_qq-1.3.0.tar.gz | 7.7 kB | Without provenance | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dynamic_config_qq-1.3.0-py3-none-any.whl | Python 3 | none | any | Details |
| dynamic_config_qq-1.3.0-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 38.6 kB
Release files / dynamic_config_qq-1.3.0.tar.gz
| Download URL | dynamic_config_qq-1.3.0.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ddd3f7a8c94d463a2bc94fb258b3058ab30a81edeb284e5f1b37c4afaa4cc0ab
|
|
BLAKE2b-256 checksum How to use checksums |
e7e3ddf07658fafa0a17e56f91387ac8400e763ba7e029939d17db62a91572a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Release files / dynamic_config_qq-1.3.0-py3-none-any.whl
| Download URL | dynamic_config_qq-1.3.0-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2dbbad3a59cafc5e5988485e4ee36b4028f97b24b6f5ce8e1992301fc1eceaa5
|
|
BLAKE2b-256 checksum How to use checksums |
4a4e081c86d4fa73bee6f36cca6d167e2362cd0d5e317d4d279d8f4775833f0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Release files / dynamic_config_qq-1.3.0-py2-none-any.whl
| Download URL | dynamic_config_qq-1.3.0-py2-none-any.whl |
|---|---|
| Size | 21.2 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
832ff224b1708e090c14c586d0fc9b0e785601611475386b0d359d7d25f57ca3
|
|
BLAKE2b-256 checksum How to use checksums |
70b68760acf3d1a7db5a78fb365b93dda76e763d9399e236eb605b2a53309786
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
Security for dynamic-config-qq 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.