2

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
2
  • Did you try to install redis < 3? Commented Feb 7, 2019 at 7:06
  • 1
    @SergeyPugach No this didn't work, I tried this devhacksandgoodies.wordpress.com/2014/07/03/… But get E: Version '2:2.8.12-1chl1~precise1' for 'redis-server' was not found. On another server I have redis-server 2.8.4 where the above code does work. I also tried the current stable version via redis.io/topics/quickstart#redis-quick-start But I got the same error. Although I can continue if an older version can be installed, I would like it to work with an up-to-date version Commented Feb 7, 2019 at 9:57

2 Answers 2

6

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)
Sign up to request clarification or add additional context in comments.

2 Comments

Don't have it installed right now. However your answer should be correct since the error is pretty clear, now I see my question again.
This answer overwrites python keywords, which might mess up scripts or interactive shells.
0

ok you could use pandas.Dataframe.todict()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.