I have a redis instance that stores data as hash. the hash key looks something like "o:t:23:45". I'm using redis-py and I am able to get list of keys.
for key in rc.scan_iter():
print(key)
b'o:t:49:15' b'o:t:50:156' b'o:t:51:159' b'o:t:52:1593' b'o:t:53:1591'
If I perform rc.hgetall(b'o:t:53:1591'), I am getting proper values.
However, when I do the following:
for key in rc.scan_iter():
rc.hgetall(key)
I get the following error:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/local/lib/python3.6/site-packages/redis/client.py", line 2717, in hgetall
return self.execute_command('HGETALL', name)
File "/usr/local/lib/python3.6/site-packages/redis/client.py", line 839, in execute_command
return self.parse_response(conn, command_name, **options)
File "/usr/local/lib/python3.6/site-packages/redis/client.py", line 853, in parse_response
response = connection.read_response()
File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 705, in read_response
raise response
redis.exceptions.ResponseError: WRONGTYPE Operation against a key holding the wrong kind of value
I tried to pass the key as str:
for key in rc.scan_iter():
rc.hgetall(str(key))
But the results I am getting are empty dicts. What am I missing here? Is it possible to iterate thru a list of keys and call hgetall() to get the values for each individual key?
EDIT: As pointed out by Itamar, the database did indeed have an entry whose key was of string type. Doing a type check before hgetall avoids the issue.