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

2024-09-26 18:02:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用redis py缓存一些数据,但是找不到一个合适的解释来解释redis.StrictRedis()redis.Redis()之间的区别。它们相等吗?

此外,在Redis Python Docs中找不到任何关于redis.StrictRedis()参数的清晰文档。 知道吗?


Tags: 数据文档pyredisdocs参数strictredis区别
2条回答

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.

以及

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年3月31日

以下是从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 py自述文件(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.

这是redis py代码中定义StrictRedislink)的一行:

StrictRedis = Redis

相关问题 更多 >

    热门问题