Python redis-py:StrictRedis() 和 Redis() 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19021765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 12:34:53  来源:igfitidea点击:

redis-py : What's the difference between StrictRedis() and Redis()?

pythonredis

提问by ABS

I want to use redis-pyfor caching some data, but I can't find a suitable explanation of the difference between redis.StrictRedis()and redis.Redis(). Are they equivalent?

我想使用redis-py来缓存一些数据,但是我找不到合适的解释redis.StrictRedis()redis.Redis(). 它们是等价的吗?

In addition, I can't find any clear documentation about redis.StrictRedis()'s arguments in Redis Python Docs. Any idea?

此外,我redis.StrictRedis()Redis Python Docs 中找不到任何关于's arguments 的明确文档。任何的想法?

采纳答案by hughdbrown

This seems pretty clear:

这似乎很清楚

 redis-py exposes two client classes that implement these commands
 The StrictRedis class attempts to adhere to the official command syntax.

and

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

Do you need backwards compatibility? Use Redis. Don't care? Use StrictRedis.

您需要向后兼容吗?使用Redis. 不在乎?使用StrictRedis.



2017-03-31

2017-03-31

Here are the specifics of the backwards compatibility, from the github.com link cited:

以下是引用的 github.com 链接中向后兼容性的细节:

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 类(StrictRedis 的子类)覆盖了其他几个命令以提供与旧版本 redis-py 的向后兼容性:

LREM:'num' 和 'value' 参数的顺序颠倒,以便 'num' 可以提供默认值零。

ZADD:Redis 在 'value' 之前指定了 'score' 参数。这些在实施时被意外交换,直到人们已经使用它之后才被发现。Redis 类期望 *args 的形式为:name1, score1, name2, score2, ...

SETEX:“时间”和“值”参数的顺序颠倒了。



回答by aliva

It's an old question but for anyone who reaches this question after google search:

这是一个老问题,但对于在谷歌搜索后遇到这个问题的人来说:

from redis-py readme (link):

来自 redis-py 自述文件(链接):

redis-py 3.0 drops support for the legacy "Redis" client class. "StrictRedis" has been renamed to "Redis" and an alias named "StrictRedis" is provided so that users previously using "StrictRedis" can continue to run unchanged.

redis-py 3.0 不再支持旧版“Redis”客户端类。“StrictRedis”已更名为“Redis”,并提供了一个名为“StrictRedis”的别名,以便之前使用“StrictRedis”的用户可以继续保持不变。

Here is the line from redis-py code which defines StrictRedis(link):

这是 redis-py 代码中定义StrictRedis链接)的行:

StrictRedis = Redis