What's the difference between the API of Redis and StrictRedis?
Question:
I’m working on a project with redis.py, I works when I connect the app to a Redis client, but failed with StrictRedis.
So, I wanna know the difference between the two, but searched with no satisfied answer.
My project is here: https://github.com/kxxoling/librorum Sorry for the Chinese annotation!
Answers:
From 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 also has no backward compatibility:
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.
So you should stick to Redis
class if you have used redis-py
for a long time – it has some commands’ argument’s order changed to seem more Pythonic (or even by accident).
Here in the source code (client.py:class Redis) you can see what have been changed.
I have found an older project also using StrictRedis and was wondering as well, looking into the answer by @Igor Hatarist it is no longer that way.
What I found: Today it implemented differently. Actually if installing the current version (v4.5.x
– March 2023) of redis-py then StrictRedis
and Redis
are actually the same: https://github.com/redis/redis-py/blob/318b114f4da9846a2a7c150e1fb702e9bebd9fdf/redis/client.py#L1289
This shows that it is not even longer implemented as class, nowadays it is just a constant (probably for backwards compatibility).
So it is no longer an override. Redis is currently a subclass of AbstractRedis
: https://github.com/redis/redis-py/blob/318b114f4da9846a2a7c150e1fb702e9bebd9fdf/redis/client.py#L845
So it does not matter which of both you use with v4.5.x
I’m working on a project with redis.py, I works when I connect the app to a Redis client, but failed with StrictRedis.
So, I wanna know the difference between the two, but searched with no satisfied answer.
My project is here: https://github.com/kxxoling/librorum Sorry for the Chinese annotation!
From 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 also has no backward compatibility:
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 ofnum
andvalue
arguments reversed such that ‘num’
can provide a default value of zero.ZADD
: Redis specifies the
score
argument beforevalue
. 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 oftime
and
value
arguments reversed.
So you should stick to Redis
class if you have used redis-py
for a long time – it has some commands’ argument’s order changed to seem more Pythonic (or even by accident).
Here in the source code (client.py:class Redis) you can see what have been changed.
I have found an older project also using StrictRedis and was wondering as well, looking into the answer by @Igor Hatarist it is no longer that way.
What I found: Today it implemented differently. Actually if installing the current version (v4.5.x
– March 2023) of redis-py then StrictRedis
and Redis
are actually the same: https://github.com/redis/redis-py/blob/318b114f4da9846a2a7c150e1fb702e9bebd9fdf/redis/client.py#L1289
This shows that it is not even longer implemented as class, nowadays it is just a constant (probably for backwards compatibility).
So it is no longer an override. Redis is currently a subclass of AbstractRedis
: https://github.com/redis/redis-py/blob/318b114f4da9846a2a7c150e1fb702e9bebd9fdf/redis/client.py#L845
So it does not matter which of both you use with v4.5.x