Watch all RedisConf 2021 sessions on demand
In order to use Redis with Python you will need a Python Redis client. In following sections, we will demonstrate the use of redis-py, a Redis Python Client. Additional Python clients for Redis can be found under the Python section of the Redis Clients page.
redis-py’s installation instructions are given in the “Installation” section of its README file. This is the easiest way to install python redis. Use the Redis Python
pip to install redis-py:
$ sudo pip install redis
You can also download the latest redis-py release from the GitHub repository to understand Python Redis, Python Lab, & Python database updates. To install Redis Python, extract the source and run the following command:
$ cd redis-py
~/redis-py$ sudo python setup.py install
The following code creates a connection to Redis using redis-py:
r = redis.Redis(
To adapt this example to your code, make sure that you replace the following values with those of your database:
hostshould be set to your database’s hostname or IP address
portshould be set to your database’s port
passwordshould be set to your database’s password
redis-py provides a connection pooling mechanism as explained in the Connection Pools section of its README file. Since connection pooling is enabled by default, no special actions are required to use it. This is a substantial benefit of Python Redis.
redis-py is the second Redis Python client that natively supported SSL. Use the
SSLConnection class or simply instantiate your connection pool using a
rediss://-URL and the
from_url method, like so:
r = redis.Redis( url='rediss://:password@hostname:port/0',
Once connected to Redis, you can start reading and writing data with Python Redis. The following code snippet writes the value
bar to the Redis key
foo, reads it back, and prints it:
# open a connection to Redis
value = r.get('foo')
The output of the above code should be:
$ python example_redis-py.py
Redis Enterprise enables running Redis Python datasets & Python Redis client in a highly available and auto-scalable manner, with predictable top performance.
The Redis Enterprise Software lets you install an enterprise grade Redis Python cluster in your environment of choice, whether an on-premises (on-prem) data-center or your preferred Redis cloud platform. It gives you full control of your data and configuration – no clustering or sharding knowledge required!
Redis Enterprise Cloud is a fully-managed cloud service for hosting and running Redis dataset without dealing with nodes, clusters, failure recovery or performance stabilization. Our technology does all that in a fully automated manner. Redis Enterprise Cloud through Redis Labs is available on all popular clouds and platforms-as-a-service.
For more information on using Redis Labs’ products and services with Redis Python please see the Howto page.