Python

Now let's try working with Redis from Python. First, make sure to install the redis-py driver:

pip install redis  

It is also recommended to install Hiredis along with redis-py. Hiredis is a parsing class written by the core Redis team, and redis-py will use Hiredis if it is present. Its use can provide a significant performance gain over the default PythonParser. The hiredis parser can be installed similarly via pip:

pip install hiredis  

Let's write a simple script to set, get, and output a simple welcome message. Create a new Python script and call it redisHelloWorld.py.

First, we will add our imports. We will need StrictRedis, as well as the sys module to pull in command-line arguments:

from redis import StrictRedis 
import sys 

Get Seven NoSQL Databases in a Week now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.