欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value

发布时间:2023/12/31 55 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。