简体   繁体   English

Redis-Py AttributeError: 'int' 对象没有属性 'items'

[英]Redis-Py AttributeError: 'int' object has no attribute 'items'

I get this error while trying to load data into Redis in Python.尝试在 Python 中将数据加载到 Redis 时出现此错误。

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我在 Github 上发现了这个问题: https : //github.com/rq/rq/issues/1014

The issue is closed and the solution should be installing RQ 0.13 I ran:问题已关闭,解决方案应该是安装我运行的 RQ 0.13:

sudo pip3 install rq

and it succesfully installed.并成功安装。 Then restarted redis-server.然后重新启动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.在这里, mapping是一个名字字典 -> 分数。
Proceed like this:像这样进行:

zkey = 'test'
dict = {}
dict['15648-barry'] = 15648
redis.zadd(zkey,dict)

好的,你可以使用 pandas.Dataframe.todict()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM