python - Redis channels -- 抓取key时的WRONGTYPE操作

标签 python django websocket redis django-channels

我正在使用 Channels Redis用于 websocket 操作。但是,我想确切地查看它在 redis 中保存的内容。这将如何完成?

这是我目前所拥有的:

>>> import redis
>>> r = redis.Redis()
>>> r.keys()
['asgi::group:chat_hello', 'asgi::group:chat_lobby', 'asgi::group:chat_hi', 'iTunes+1068285837']
>>> r.get('asgi::group:chat_hello')
redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value

最佳答案

首先,检查有问题的 key 的类型:

>>> r.type('asgi::group:chat_hello')
'zset'

它是 zet 类型,或 sorted set在redis中。要查看已排序集合的内容,您可以执行以下操作:

# r.zrange(key, 0, -1) --  0, 1 specifies the starting and ending index, 
                       --  where 0 is the start and -1 is the end
>>> r.zrange('asgi::group:chat_newplace', 0, -1)
['specific.AUWRSlpx!NjGkQvODgPHx']

关于python - Redis channels -- 抓取key时的WRONGTYPE操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52582339/

相关文章:

python - 一种更Pythonic的方法,将一列拆分为多列并对其中两列求和

javascript - 如何在 websocket 上 .append() 新消息以使用 CSS 样式页面?

node.js - Bitfinex 的 Websocket API "hello world"导致 ECONNREFUSED 错误

python - 堆叠两个不同维度的稀疏矩阵

python - 操纵 Pandas 数据框以显示所需的输出

python - django-paypal 突然停止接收来自 Paypal 的信号

python - Django 模型翻译查询回退

python - 如何结合 Django 的 ‘LoginRequiredMixin’ 和表单工具的 ‘FormPreview’ ?

python - 为什么我应该使用 `mod_wsgi` 而不是通过 python 启动?

ios - STOMP Websocket 有时没有响应