What is Redis streams??

(Definition from Redis.io )

A Redis stream is a data structure that acts like an append-only log. You can use streams to record and simultaneously syndicate events in real time. Examples of Redis stream use cases include:

  • Event sourcing (e.g., tracking user actions, clicks, etc.)
  • Sensor monitoring (e.g., readings from devices in the field)
  • Notifications (e.g., storing a record of each user’s notifications in a separate stream)

Redis generates a unique ID for each stream entry. You can use these IDs to retrieve their associated entries later or to read and process all subsequent entries in the stream.

Redis streams support several trimming strategies (to prevent streams from growing unbounded) and more than one consumption strategy (see XREAD, XREADGROUP, and XRANGE).

Setup your training environment

There is two ways to do that

Option 1 – Use your own Redis environment

for that you will have to install Redis:

1. Download and install Redis. The minimum version is 5.0.3 for this course.

2. Confirm you have a viable Python environment:

1. Confirm that your Python version is 3.6.5 or above:

$ python3 --version Python 3.6.5

2. Confirm pip 19.01 or above:

$ pip3 --version
pip 19.0.1 from /usr/lib/python3.6/site-packages/pip (python 3.6)

3. Download source code from GitHub

4. Follow the instructions in the README file to setup a Python virtual environment and configure and test your connection to Redis

Option 2 (our case )- Run the Lab in your local Docker environment

If you have access to a Docker environment, a Docker image has been created that encapsulates an IDE, Redis Server, source code and sample data. Follow these instructions to use the image.

check how to install docker for Windows on your Windows 10 machine following my previous Blog

1. Run the Docker container

$ docker run --rm --name redis-lab -p:8888:8888 redisuniversity/ru202-lab

2. Point your browser to


Note: In the Docker environment, you don’t need to set up a Python virtual environment. Everything is configured and ready to go.

Some example with Redis Streams

Now you are able use the lab you cab tests some command or directly follow the course in Redis university to better understand how to use Redis streams.

Some scripts were especially developed to give you example of Redis streams usage ( you can check the consumers and producers roles in Redis.io documentation,you got also two terminal in order to perform your tests.


Example of XADD command and how to retrieve your stream entries

Basic commands

  • XADD adds a new entry to a stream.
  • XREAD reads one or more entries, starting at a given position and moving forward in time.
  • XRANGE returns a range of entries between two supplied entry IDs.
  • XLEN returns the length of a stream.

See the complete list of stream commands.


Now you have an environment to perform your tests and discover Redis streams power, you can practice freely but I advice you to follow the Redis university workshop which very complete and will allow you to unleash all its capabilities to achieve great project using this tool!