【问题标题】:TypeError: unbound method sadd() must be called with StrictRedis instance as first argument (got str instance instead)TypeError:必须使用 StrictRedis 实例作为第一个参数调用未绑定的方法 sadd()(改为获取 str 实例)
【发布时间】:2015-07-16 00:43:46
【问题描述】:

我在 python 应用程序中有以下内容:

from redis import Redis, StrictRedis

......
r = line.split(" ")[0]
StrictRedis.sadd('my_set', r)

我收到标题中的错误。我做错了什么?

【问题讨论】:

    标签: python redis


    【解决方案1】:

    StrictRedis(host='localhost', port=6379, db=0, password=None, socket_timeout=None, connection_pool=None, charset='utf-8', errors='strict', unix_socket_path=None)

    我认为你必须先创建StrictRedis 实例

    sred = StrictRedis() #with your parameteres
    sred.sadd('my_set', r)
    

    【讨论】:

    • 谢谢,成功了。如果我在函数中创建实例,在函数执行时它是否不复存在?
    • 函数内的变量是局部范围的(只能在该函数内使用)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-18
    • 2023-04-06
    • 1970-01-01
    • 2017-12-09
    • 2015-12-01
    • 2018-08-12
    相关资源
    最近更新 更多