redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value
完整報錯如下:
(Python3.6) appleyuchi@ubuntu19:有序集合$ python example_of_range.py?
Traceback (most recent call last):
? File "example_of_range.py", line 3, in <module>
? ? rank_100_1000 = client.zrange('user_online_status', 0, 4, desc=True, withscores=True)
? File "/home/appleyuchi/anaconda3/envs/Python3.6/lib/python3.6/site-packages/redis/client.py", line 2496, in zrange
? ? score_cast_func)
? File "/home/appleyuchi/anaconda3/envs/Python3.6/lib/python3.6/site-packages/redis/client.py", line 2622, in zrevrange
? ? return self.execute_command(*pieces, **options)
? File "/home/appleyuchi/anaconda3/envs/Python3.6/lib/python3.6/site-packages/redis/client.py", line 839, in execute_command
? ? return self.parse_response(conn, command_name, **options)
? File "/home/appleyuchi/anaconda3/envs/Python3.6/lib/python3.6/site-packages/redis/client.py", line 853, in parse_response
? ? response = connection.read_response()
? File "/home/appleyuchi/anaconda3/envs/Python3.6/lib/python3.6/site-packages/redis/connection.py", line 717, in read_response
? ? raise response
redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value
?
錯誤原因:
redis的存儲數據的類型和代碼試圖讀取該數據時使用的函數不一致.
?
排查方法和解決方案:
localhost:6379> type user_online_status
hash
?
由于代碼中使用了client.zrevrange
這個函數是用來讀取zset的,而不是hset的,所以要么重新檢查導入數據的方式,
要么刪掉zrevrange,改用hget函數
?
總結
以上是生活随笔為你收集整理的redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL中concat函数的用法(连接
- 下一篇: 【UE4】如何获取/下载虚幻4(Unre