Redis is an in-memory data structure store that can serve as a database, cache, or message broker. Here it provides asynchronous messaging: components publish messages to a queue instead of communicating directly, improving flexibility, performance, and scalability. section 21.0 section 21.1
A practical Redis messaging workflow uses separate containers for the queue, publisher, and subscriber:
- Create a Docker network and start a Redis server listening on port 6379. section 21.1
- Run the Redis CLI to publish the message "ping" repeatedly on the channel "channel21". section 21.1
- Start an interactive subscriber and observe each published message arriving through the channel. section 21.1
Publish and subscribe with containers
Start Redis with the diamol/redis:2e image, publish "ping" 50 times at five-second intervals using the Redis CLI, and subscribe to channel21 in another container. The subscriber receives a copy of every published message. section 21.1
# create the network - on Linux containers: docker network create ch21 # OR Windows Server containers: docker network create -d nat ch21 # run the Redis server: docker container run -d --name redis --network ch21 diamol/redis:2e # check that the server is listening: docker container logs redis --tail 1
Use the container commands to create the network, launch Redis, and verify from the logs that the server is listening. section 21.1





