Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

redis

People also ask

What does Redis do in Python?

Redis is an in-memory key-value pair database typically classified as a NoSQL database. Redis is commonly used for caching, transient data storage and as a holding area for data during analysis in Python applications. Redis is an implementation of the NoSQL database concept.

Does Redis work with Python?

In the same way that you would run python at the command line, you can run redis-cli to jump into an interactive REPL (Read Eval Print Loop) where you can run client commands directly from the shell.

Is Redis-PY async?

Async support was introduced in redis-py 4.2. x thanks to aioredis, which necessitates this change. We will continue to maintain 3.6 support as long as possible - but the plan is for redis-py version 4.4+ to officially remove 3.6.


EDIT: They are now equivalent:

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.

Original answer: 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.



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