Redis pub/sub

Redis pub/sub is a messaging mechanism in which publishers send messages to named channels and subscribers receive messages from channels they are listening to. It provides immediate delivery to active subscribers but does not retain messages for disconnected subscribers.

Minimal example

go
sub := client.PSubscribe(ctx, "user:*")
defer sub.Close()
if _, err := sub.Receive(ctx); err != nil {
    return err
}
for msg := range sub.Channel() {
    fmt.Println(msg.Channel, msg.Payload)
}

Learn this concept

Lesson 5.4 · Redis pattern subscriptions

Used in exercises

Exercise 5.5 · Per-user order event bridge Exercise 5.8 · Rider assignment worker Exercise 5.11 · Order location stream Exercise 5.15 · Per-user Redis replay log
Prerequisite conceptsGo contextChannels