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

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

我想使用Redis的-PY缓存一些数据,但我无法找到之间的差异的一个合适的解释redis.StrictRedis()redis.Redis()。它们相等吗?

另外,redis.StrictRedis()Redis Python Docs中找不到关于的参数的任何清晰文档。任何想法?

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

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


回答 0

这似乎很清楚

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

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

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


2017-03-31

以下是从github.com链接引用的向后兼容性的详细信息:

除了上述更改之外,Redis类是StrictRedis的子类,它重写了其他一些命令以提供与较早版本的redis-py的向后兼容性:

LREM:“ num”和“ value”参数的顺序颠倒,因此“ num”可以提供默认值零。

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

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


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.


2017-03-31

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

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.



回答 1

这是一个古老的问题,但对于在Google搜索后遇到此问题的任何人:

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

redis-py 3.0放弃了对旧版“ Redis”客户端类的支持。“ StrictRedis”已重命名为“ Redis”,并提供了一个名为“ StrictRedis”的别名,以便以前使用“ StrictRedis”的用户可以继续运行。

这是定义StrictRedislink)的redis-py代码的代码:

StrictRedis = Redis

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

from redis-py readme (link):

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.

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

StrictRedis = Redis