single |
redis-py
========
The Python interface to the Redis key-value store.
Python 2 Compatibility Note
---------------------------
redis-py 3.5.x will be the last version of redis-py that supports Python 2.
The 3.5.x line will continue to get bug fixes and security patches that
support Python 2 until August 1, 2020. redis-py 4.0 will be the next major
version and will require Python 3.5+.
Installation
------------
redis-py requires a running Redis server. See [Redis's quickstart
] for installation instructions.
redis-py can be installed using `pip` similar to other Python packages. Do
not use `sudo`
with `pip`. It is usually good to work in a
[virtualenv] or
[venv] to avoid conflicts with other package
managers and Python projects. For a quick introduction see
[Python Virtual Environments in Five Minutes].
To install redis-py, simply:
.. code-block:: bash
$ pip install redis
or from source:
.. code-block:: bash
$ python setup.py install
Getting Started
---------------
.. code-block:: pycon
>>> import redis
>>> r = redis.Redis(host='localhost', port=6379, db=0)
>>> r.set('foo', 'bar')
True
>>> r.get('foo')
b'bar'
By default, all responses are returned as `bytes` in Python 3 and `str` in
Python 2. The user is responsible for decoding to Python 3 strings or
Python 2
unicode objects.
If **all** string responses from a client should be decoded, the user can
specify `decode_responses=True` to `Redis.__init__`. In this case, any
Redis command that returns a string type will be decoded with the
`encoding`
specified.
Upgrading from redis-py 2.X to 3.0
----------------------------------
redis-py 3.0 introduces many new features but required a number of
backwards
incompatible changes to be made in the process. This section attempts to
provide an upgrade path for users migrating from 2.X to 3.0.
Python Version Support
^^^^^^^^^^^^^^^^^^^^^^
redis-py 3.0 supports Python 2.7 and Python 3.5+.
Client Classes: Redis and StrictRedis
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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.
The 2.X "Redis" class provided alternative implementations of a few
commands.
This confused users (rightfully so) and caused a number of support issues.
To
make things easier going forward, it was decided to drop support for these
alternate implementations and instead focus on a single client class.
2.X users that are already using StrictRedis don't have to change the class
name. StrictRedis will continue to work for the foreseeable future.
2.X users that are using the Redis class will have to make changes if they
use any of the following commands:
* SETEX: The argument order has changed. The new order is (name, time,
value).
* LREM: The argument order has changed. The new order is (name, num,
value).
|