A Django Admin接口,用于Redis服务器,可选Redis Sentinel支持
项目描述
介绍
使用< cite>django-redis-admin cite>,您可以查看(并在将来,编辑)您的Redis数据库。它支持简单服务器、主从设置和sentinel设置。
管理器通过创建一个< cite>RedisQueryset cite>来工作,该< cite>RedisQueryset cite>伪造Django模型和查询集,以便< cite>ModelAdmin cite>认为它正在使用一个常规数据库支持的模型。
由于Redis只支持基本类型,因此库允许可选的< cite>base64 cite>编码/解码和< cite>json cite>编码/解码。
虽然我并不建议将其用作常规查询集来访问Redis。除了查询数据之外,它还执行一些额外的查询(例如获取空闲数据)并执行一些自动转换步骤。
需求
Python < cite>3.6 cite>及更高版本
Django(已测试2.1版本,可能支持支持Python 3的任何版本)
Python-redis(< cite>pip install redis cite>)
安装
< cite>django-redis-admin cite>可以通过pip安装。
pip install django-redis-admin
然后只需将< cite>redis_admin cite>添加到您的< cite>INSTALLED_APPS cite>中。
可选地,如果您有多个和/或非标准(即非localhost)redis服务器,请配置您的服务器。
以下是几个示例配置。默认设置始终可以在< cite>redis_admin/settings.py cite>中找到
您可以使用以下命令运行演示项目
cd test_redis_admin
python manage.py runserver
默认用户名/密码是< cite>admin cite>/< cite>admin cite>: http://localhost:8080/admin/
基本配置
# https://redis-py.pythonlang.cn/en/latest/index.html#redis.Redis
REDIS_SERVERS = dict(
localhost=dict(),
)
显式配置
# https://redis-py.pythonlang.cn/en/latest/index.html#redis.Redis
REDIS_SERVERS = dict(
redis_server_a=dict(host='127.0.0.1', port=6379, db=0),
)
主从配置
# https://redis-py.pythonlang.cn/en/latest/index.html#redis.Redis
REDIS_SERVERS = dict(
redis_server_a=dict(
master=dict(host='master_hostname', port=6379, db=0),
slave=dict(host='slave_hostname', port=6379, db=0),
)
)
Sentinel配置
# The `REDIS_SENTINELS` setting should be a list containing host/port
# combinations. As documented here:
# https://github.com/andymccurdy/redis-py/blob/master/README.rst#sentinel-support
REDIS_SENTINELS = [('server_a', 26379), ('server_b', 26379)]
# The `REDIS_SENTINEL_OPTIONS` are the extra arguments to
# `redis.sentinel.Sentinel`:
# https://github.com/andymccurdy/redis-py/blob/cdfe2befbe00db4a3c48c9ddd6d64dea15f6f0db/redis/sentinel.py#L128-L155
REDIS_SENTINEL_OPTIONS = dict(socket_timeout=0.1)
# The `service_name` is used to find the server within the Sentinel
# configuration. The dictionary key will be used as the name in the admin
# https://redis-py.pythonlang.cn/en/latest/index.html#redis.Redis
REDIS_SERVERS = dict(
name_in_admin=dict(service_name='name_in_sentinel'),
other_server=dict(service_name='other_server'),
)
Base64和/或JSON解码
作为一个方便的选项,所有值都可以可选地进行 base64 和/或 json 编码。为了配置这个选项,可以指定一个正则表达式,该表达式将与键进行匹配。
# For all keys
REDIS_JSON_KEY_RE = '.*'
REDIS_BASE64_KEY_RE = '.*'
# Keys starting with a pattern:
REDIS_BASE64_KEY_RE = '^some_prefix.*'
# Keys ending with a pattern:
REDIS_JSON_KEY_RE = '.*some_suffix$'
如果需要特定的 json 解码器,可以指定 json 模块。该模块需要是可导入的,并具有 dumps 和 loads 方法。默认情况下,它简单地导入 json 模块
REDIS_JSON_MODULE = 'json'
表示裁剪
在Django Admin列表视图中,默认情况下会裁剪值以防止出现非常长的行。可以通过以下方式调整此大小
REDIS_REPR_CROP_SIZE = 150
待办事项
允许保存值
允许删除值
支持Redis位图
支持Redis HyperLogLogs
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分发
构建分发
django-redis-admin-0.3.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | e49048c315ee8e054e906bd5644d30f32039b1de79f5221044e0903ab24f121f |
|
MD5 | 39fa8b7abbf345b83a8ea9234d42ff1b |
|
BLAKE2b-256 | 4eb6f0e2b392fba662aca4d983b17f1727749a4958154e00421e006a4cf1b8a0 |
django_redis_admin-0.3.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d4752f9a279f1203d92355919e5276d47b11349dad54570ec88bdc4a96b28e6d |
|
MD5 | 48bbffb9aa9c27cac2593acdce2103cd |
|
BLAKE2b-256 | 57aff41424fa4b0534184c611e304aa5ebd0c86f7f7116a48713f0626e30f350 |