Redis通道-尝试获取密钥时进行WRONGTYPE操作

时间:2018-09-30 21:27:16

标签: 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

1 个答案:

答案 0 :(得分:1)

首先,检查相关密钥的类型:

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

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

# 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']