Getting Started with Python and Redis

This is  a small tutorial to start using Redis with Python. We will look at the steps that tell you how to install Redis in your local ubuntu machine. As we are compiling from source this should also represent how to install in any linux distribution. Then, we can look at some basic commands in Redis and get a feel of the Redis commands. Finally, we will install the Redis-py module and see how we can interface with the Redis module from Python.

Before going through this tutorial, please go through our Redis infographic to get an overview of the Redis module and how to approach it. We also have a webinar on developing a Redis module.

I am using an ubuntu machine. Let us start with the installation of Redis.


Install build essentials which have C and C++ compilers and other GNU C libraries which will help us in the installation later.


Tcl is also needed to run Redis.


Download the Redis source and untar it.


We will need to now compile from source.


Once this is done, there will be a set of scripts that will be created in the utils folder which can be used to install the service.


To access Redis, we will need the redis-cli.


We can set and get key values using the “SET” and “GET” keywords.


Let's now install the Python module and try to see if we can access the Redis server from Python.

Let's test the Redis server with the Python.


This was a basic tutorial about using Python with Redis. Next, we will lay a frontend for making a twitter client using Flask as the middleware and Redis in the backend.

References:

agiliq, getting started with redis and python
digitalocean, how to install and use redis

About the Author

Joydeep
Joydeep Bhattacharjee is a Category Head (Python) at HackerEarth. He likes to dabble in all things tech and is passionate about open source.
1
Share