pythonredisredis-py

What's the difference between the API of Redis and StrictRedis?


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!


Solution

  • 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.