Redis Streams is a Redis data type that represents a log, so you can add new information and message in an append-only mode. Redis Streams lets you build “Kafka-like” applications, which can:
- Create applications that publish and consume messages. Nothing extraordinary here, you could already do that with Redis Pub/Sub.
- Consume messages that are published even when the client application (consumer) is not running. This is a big difference from Redis Pub/Sub.
- Consume messages starting from a specific point. For example, read the whole history or only new messages.
In addition, Redis Streams has the concept of consumer groups. Redis Streams consumer groups, like the similar concept in Apache Kafka, allows client applications to consume messages in a distributed fashion (multiple clients), making it easy to scale and create highly available systems.
Let’s dive under the covers and see Redis Streams through the lens of RedisInsight. You will see how to use Lettuce Java client to publish and consume messages using consumer groups.This is the first basic example that uses a single consumer.
To install RedisInsight on your local system, you need to first download the software from Redis Labs website.
Click this link to access a form that allows you to select the operating system of your choice.
Run the installer. After the web server starts, open http://YOUR_HOST_IP:8001 and add a Redis database connection.
Select "Connect to a Redis database"
Enter the requested details, including Name, Host (endpoint), Port, and Password. Then click “ADD REDIS DATABASE”.
Open a new terminal and run this command:
The consumer will start and consume the message you just posted, and wait for any new messages.
In the first terminal, post 100 new messages:
Let us try to visualise using the RedisInsight browser tool. Make sure ‘Stream Data’ is selected and select any one of the streams. You’ll see a table showing data in that stream along with a timestamp of when each entry was added.
To see the processing side of the stream select ‘Stream Data”. You will see 105 records under the streaming data.
Click on “Consumer Groups” to see application_1 as promising consumer.
RedisInsight also provide you to select fields as shown under “View Columns” section.