Skip to content

Instantly share code, notes, and snippets.

@leoantony72
Created October 19, 2022 15:14
Show Gist options
  • Save leoantony72/63a7e56b758d933a354606ddc5475aa6 to your computer and use it in GitHub Desktop.
Save leoantony72/63a7e56b758d933a354606ddc5475aa6 to your computer and use it in GitHub Desktop.
Go Redis Pub/Sub
package config
import (
"context"
// "fmt"
"go/chat/utils"
"github.com/go-redis/redis/v9"
)
var Ctx = context.Background()
var Conn redis.Client
func PubSub() {
SERVERID := utils.EnvVariable("SERVERID")
subscriber := Conn.Subscribe(Ctx, SERVERID)
for {
msg, err := subscriber.ReceiveMessage(Ctx)
if err != nil {
panic(err)
}
// fmt.Printf("message from pub/sub : %v", msg.Payload)
broadcast <- msg
// ...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment