This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
JISQueueing/server/socket/redis.go

36 lines
515 B
Go

2020-01-31 03:24:23 +07:00
package socket
import (
"github.com/go-redis/redis/v7"
)
var client *redis.Client
var channel *redis.PubSub
type Message struct {
ID int
Name string
Email string
}
func StartRedisServer(addr string) {
client = redis.NewClient(&redis.Options{
Addr: addr,
})
_, err := client.Ping().Result()
if err != nil {
panic(err)
}
channel = client.Subscribe("qq")
_, err = channel.Receive()
if err != nil {
panic(err)
}
}
func sendMessageToRedisChannel(msg Message) {
client.Publish("qq", msg)
}