Redis Publish/subscribe
Redis implements a publish/subscribe messaging mechanism.
Its concept is simple: a publisher sends a message on a channel. Multiple subscribers receive it.
Subscribe to a channel using
SUBSCRIBE <channel>
Publish to a channel using
PUBLISH <channel> <message>
Example:
SUBSCRIBE dogs
In another redis-cli
window, type:
PUBLISH dogs "Roger"
Messages will be sent to the subscribers, and they’ll by default display the kind of event, the channel, and the message:
Subscribers can listen on multiple channels:
SUBSCRIBE dogs cats
and will receive messages coming from all of them.
→ I wrote 17 books to help you become a better developer:
- C Handbook
- Command Line Handbook
- CSS Handbook
- Express Handbook
- Git Cheat Sheet
- Go Handbook
- HTML Handbook
- JS Handbook
- Laravel Handbook
- Next.js Handbook
- Node.js Handbook
- PHP Handbook
- Python Handbook
- React Handbook
- SQL Handbook
- Svelte Handbook
- Swift Handbook
Also, JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025