# Redis Publish/subscribe

> Learn how Redis publish/subscribe messaging works, using the SUBSCRIBE and PUBLISH commands to send a message on a channel to multiple subscribers at once.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2020-07-31 | Topics: [Redis](https://flaviocopes.com/tags/redis/) | Canonical: https://flaviocopes.com/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
```

![Redis CLI terminal showing SUBSCRIBE dogs command with confirmation messages](https://flaviocopes.com/images/redis-publish-subscribe/Screenshot_2020-03-30_at_18.37.50.png)

In another `redis-cli` window, type:

```
PUBLISH dogs "Roger"
```

![Redis CLI terminal showing PUBLISH commands sending Roger and Syd messages to dogs channel](https://flaviocopes.com/images/redis-publish-subscribe/Screenshot_2020-03-30_at_18.37.18.png)

Messages will be sent to the subscribers, and they'll by default display the kind of event, the channel, and the message:

![Subscriber terminal displaying received messages from dogs channel showing Roger and Syd](https://flaviocopes.com/images/redis-publish-subscribe/Screenshot_2020-03-30_at_18.37.26.png)

Subscribers can listen on multiple channels:

```
SUBSCRIBE dogs cats
```

and will receive messages coming from all of them.
