gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 11:14:58 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com