NavigationContentFooter
Suggest an edit

Using Publish/Subscribe messaging with Redis™

The Publish/Subscribe feature is available with Redis™ 6 and 7.

Pub/Sub is a highly scalable messaging model fit to handle large amounts of data and that enables asynchronous communication on low bandwidth.

The model decouples the publishers, the clients sending a message, from the subscribers, the one or several clients receiving the message. Messages are published to a third component, the message broker, whose job is to forward messages from publishers to subscribers under topics.

Topics describe the data contained within messages, allowing subscribers to choose which messages to receive based on the subject of the topic. For example, under a topic named /weather-paris one could expect to find data about the weather in Paris.

To implement Pub/Sub using Redis, you can run commands such as PUBLISH and SUBSCRIBE.

Security & Identity (IAM)

To perform certain actions described below, you must either be the Owner of the Organization in which the actions will be performed or an IAM user with the necessary permissions.

Requirements
  • You have an account and are logged into the Scaleway console
  • You have a Redis™ Database Instance with Redis™ version 6 or 7
  1. Connect to your Redis™ Database Instance.
  2. Subscribe to a topic. In this tutorial, we will use temperature as an example of topic.
    > SUBSCRIBE temperature
    Reading messages... (press Ctrl-C to quit)
    1) "subscribe"
    2) "myqueue"
    3) (integer) 1
  3. Publish to the topic in a separate client. You can connect to the same Redis™ Database Instance in a different terminal to do so.
    > PUBLISH temperature monday/12C
    (integer) 1
  4. Read the message in the first terminal, where you are subscribed to the temperature topic. You can see the update in real-time.
    > SUBSCRIBE temperature
    1) "subscribe"
    2) "temperature"
    3) (integer) 1
    1) "message"
    2) "temperature"
    3) "monday/12C"
    All other subscribers of the temperature topic will receive the same messages.
Tip

Refer to the official Redis Pub/Sub documentation page for more commands and use cases.

Cloud Products & Resources
  • Scaleway Console
  • Compute
  • Storage
  • Network
  • IoT
  • AI
Dedicated Products & Resources
  • Dedibox Console
  • Dedibox Servers
  • Network
  • Web Hosting
Scaleway
  • Scaleway.com
  • Blog
  • Careers
  • Scaleway Learning
Follow us
FacebookTwitterSlackInstagramLinkedin
ContractsLegal NoticePrivacy PolicyCookie PolicyDocumentation license
© 1999-2024 – Scaleway SAS