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函数的用法(连接
- 下一篇: $lookup做关联表查询