gpt4 book ai didi

python - Redis 和 StrictRedis 的 API 有什么区别?

转载 作者:可可西里 更新时间:2023-11-01 11:12:02 31 4
gpt4 key购买 nike

我正在使用 redis.py 开发一个项目,我在将应用程序连接到 Redis 客户端时工作,但使用 StrictRedis 时失败了。

所以,我想知道两者之间的区别,但搜索没有满意的答案。

我的项目在这里:https://github.com/kxxoling/librorum对不起中文注释!

最佳答案

来自 redis-py README :

The official Redis command documentation does a great job of explaining each command in detail. redis-py exposes two client classes that implement these commands.
The StrictRedis class attempts to adhere to the official command syntax.

StrictRedis 也没有向后兼容性:

In addition to the changes above, the Redis class, a subclass of StrictRedis, overrides several other commands to provide backwards compatibility with older versions of redis-py:

  • LREM: Order of num and value arguments reversed such that 'num' can provide a default value of zero.
  • ZADD: Redis specifies the score argument before value. These were swapped accidentally when being implemented and not discovered until after people were already using it. The Redis class expects *args in the form of: name1, score1, name2, score2, ...
  • SETEX: Order of time and value arguments reversed.

因此,如果您长期使用 redis-py,您应该坚持使用 Redis 类 - 它已将一些命令的参数顺序更改为看起来更像 Pythonic(或即使是偶然的)。

在源代码 ( client.py:class Redis ) 中,您可以看到发生了什么变化。

关于python - Redis 和 StrictRedis 的 API 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28364487/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com