一种具有选择性再分配哨兵支持的再分配伺服器的Django admin接口
django-redis-admin的Python项目详细描述
简介
使用django redis admin,您可以查看(并在将来编辑)您的redis 数据库。它支持简单的服务器、主从设置和哨兵设置。
管理员通过创建一个仿造django模型和 querysets使modeladmin认为它使用的是常规的数据库支持模型。
由于Redis只支持基本类型,库允许可选的base64 编码/解码和json编码/解码。
但我不建议将其用作访问Redis的常规queryset在 除了查询数据外,它还执行一些通常不执行的额外查询 需要(例如获取空闲数据)并执行一些自动转换步骤
要求
- python3.6及以上
- django(用2.1测试过,可能适用于任何支持 Python3)
- python redis(pip安装redis)
安装
django redis admin可以通过PIP安装。
pip install django-redis-admin
然后只需将redis管理员添加到安装的应用程序中
如果有多个和/或非标准服务器,也可以配置服务器 (即非本地主机)redis服务器
下面是几个配置示例。默认设置始终可以是
可在redis_admin/settings.py中找到
您可以使用以下命令运行演示项目: 默认用户名/密码是admin/admin:http://localhost:8080/admin/ 作为一个方便的选项,所有值都可以选择base64和/或json
编码的。要配置它,可以指定一个正则表达式
与钥匙匹配。 如果需要特定的json解码器,则可以指定json模块。
模块需要是可导入的,并且有一个dumps和loads方法。由
默认情况下,它只是导入json模块: 在django管理列表视图中,默认情况下会裁剪这些值,以防止出现真正的长行。此尺寸可通过以下方式调整:cd test_redis_admin
python manage.py runserver
基本配置
# https://redis-py.readthedocs.io/en/latest/index.html#redis.RedisREDIS_SERVERS=dict(localhost=dict(),)
显式配置
# https://redis-py.readthedocs.io/en/latest/index.html#redis.RedisREDIS_SERVERS=dict(redis_server_a=dict(host='127.0.0.1',port=6379,db=0),)
主从配置
# https://redis-py.readthedocs.io/en/latest/index.html#redis.RedisREDIS_SERVERS=dict(redis_server_a=dict(master=dict(host='master_hostname',port=6379,db=0),slave=dict(host='slave_hostname',port=6379,db=0),))
哨兵配置
# 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-supportREDIS_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-L155REDIS_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.readthedocs.io/en/latest/index.html#redis.RedisREDIS_SERVERS=dict(name_in_admin=dict(service_name='name_in_sentinel'),other_server=dict(service_name='other_server'),)
base64和/或json解码
# For all keysREDIS_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$'
REDIS_JSON_MODULE='json'
表示裁剪
REDIS_REPR_CROP_SIZE=150
待办事项
- 允许保存值
- 允许删除值
- 支持redis位图
- 支持redis超日志