hset()
中明确指定你正在提供映射。在你的情况下:r.hset("myKey", mapping=info)
替代
r.hset("myKey", info)
hmset(name, mapping)
: 给定一个哈希表名字("myKey"
)和一个字典(info
),设置所有的键值对。
hset(name, key=None, value=None, mapping=None)
: 给定一个哈希表名字("myKey"
)、一个键和一个值,设置该键的值。或者,给定一个字典(mapping=info
),设置字典中所有的键值对到哈希表中。
来源:https://redis-py.readthedocs.io/en/stable/
如果这些方法不能正常工作,也许您需要更新库?
我正在使用Redis.hmset():
redis.hmset('myKey', info)
Redis.hset()
,则不会收到以下警告。redis.hset('myKey', key=None, value=None, mapping=info)
redis.hset()
将把info
中的所有key
和value
映射设置为myKey
。field/value
对在hmset
中执行多个hset
。r.hset('myKey', 'users', 10)
r.hset('myKey', 'timestamp', datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'))
r.hset('myKey', 'yet-another-field', 'yet-another-value')
hset("myKey", mapping=info)
。 - chashmapping
kwarg 是在 3.5.0 版本中添加的(2020 年 4 月 29 日)。如果您的版本较旧,则需要按照 @Ersoy 的建议进行操作。 - chashredis-3.5.2
版本后,PyCharm中的警告消失了。现在我不知道该接受哪个答案了。两个都是正确的。为了清晰起见,我选择Ersoy的答案。谢谢你们俩。 - Houman