我正在使用 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/