Created
October 19, 2022 15:14
-
-
Save leoantony72/63a7e56b758d933a354606ddc5475aa6 to your computer and use it in GitHub Desktop.
Go Redis Pub/Sub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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