(redis-py 4.3) redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value

(redis-py 4.3) redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value

sismember 抛出错误:

r.sismember('somename/fooset', 'blah')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/myhome/lib/python3.9/site-packages/redis/commands/core.py", line 3251, in sismember
    return self.execute_command("SISMEMBER", name, value)
  File "/myhome/lib/python3.9/site-packages/redis/client.py", line 1227, in execute_command
    return conn.retry.call_with_retry(
  File "/myhome/lib/python3.9/site-packages/redis/retry.py", line 46, in call_with_retry
    return do()
  File "/myhome/lib/python3.9/site-packages/redis/client.py", line 1228, in <lambda>
    lambda: self._send_command_parse_response(
  File "/myhome/lib/python3.9/site-packages/redis/client.py", line 1204, in _send_command_parse_response
    return self.parse_response(conn, command_name, **options)
  File "/myhome/lib/python3.9/site-packages/redis/client.py", line 1243, in parse_response
    response = connection.read_response()
  File "/myhome/lib/python3.9/site-packages/redis/connection.py", line 842, in read_response
    raise response
redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value

姓名'somename/foo'下的ZSET是:

r.zrange('somename/fooset', 0, -1, desc=True, withscores=True)
# [(b'blah', 2.0), (b'hlah', 1.0)]

r.zscore('somename/fooset', 'blah') returns 正确的类型。

SISMEMBER 适用于 Redis 集合。 ZRANGE 和 ZSCORE 命令 - Sorted Sets.

因此出现错误。与 Python.

无关

如果您的键确实是一个有序集 - 您可以使用 ZSCORE 来识别 id 元素是一个有序集的成员,如 described here.