I get this error while trying to load data into Redis in Python.
This is the code:
zkey = 'test'
k = 15648
nval = '15648-barry'
redis.zadd(zkey, k, nval)
And this is the error:
Traceback (most recent call last):
File "test.py", line 131, in main
redis.zadd(zkey, k, nval)
File "/usr/local/lib/python3.6/dist-packages/redis/client.py", line 2320, in zadd
for pair in iteritems(mapping):
File "/usr/local/lib/python3.6/dist-packages/redis/_compat.py", line 122, in iteritems
return iter(x.items())
AttributeError: 'int' object has no attribute 'items'
I found this issue on Github: https://github.com/rq/rq/issues/1014
The issue is closed and the solution should be installing RQ 0.13 I ran:
sudo pip3 install rq
and it succesfully installed. Then restarted redis-server.
However I'm still getting the same error.
Is there another solution to this problem?
Specs:
Python 3.6.7
RQ 0.13
Redis-Server 4.0.9
Pip3 redis 3.1.0
Ubuntu 18.04.1 LTS
Do not install install anything new.
Based upon the errors, and going to the specified file, you will find this:
# "/usr/local/lib/python3.6/dist-packages/redis/client.py"
def zadd(self, name, mapping, nx=False, xx=False, ch=False, incr=False):
They need names & scores to be passed as a dictionary.
Here, mapping
is a dictionary of names -> scores.
Proceed like this:
zkey = 'test'
dict = {}
dict['15648-barry'] = 15648
redis.zadd(zkey,dict)