Application overview

Let’s see some of the Redis Streams features in action and learn with the help of an application.

This application consists of the following components:

  • A REST endpoint to accept user data: A JSON payload representing user details is sent to a REST endpoint (using HTTP POST) and the HTTP handler uses the XAdd method to send this to a Redis stream.

  • A Redis stream consumer to process user data: A consumer application uses the XReadGroup method to retrieve and process user data. In this case, the processing involves saving the user details in a Redis hash using the HSet method.

  • A REST endpoint to expose the pending messages count: To make it possible to examine the state of Redis streams consumer groups, the number of messages is exposed by a REST endpoint.

Code explanation

Let’s walk through the important parts of the code. First, let’s take a look at the REST API that accepts user data and sends them to a Redis stream.

Imports

Here are some of the package imports:

Get hands-on with 1400+ tech skills courses.