package main
import (
"fmt"
"github.com/go-redis/redis"
)
func main() {
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
handlSub(*client)
}
func handlSub(client redis.Client){
sub := client.Subscribe("1_message")
for{
iface, err := sub.Receive()
if err != nil {
fmt.Println(err)
}
// Should be *Subscription, but others are possible if other actions have been
// taken on sub since it was created.
switch iface.(type) {
case *redis.Subscription:
fmt.Println("sub")
case *redis.Message:
fmt.Println(iface)
case *redis.Pong:
fmt.Println("pong")
default:
fmt.Println("err")
}
}
}
redis-go возвращает сообщение в таком формате. Как получить сообщение (test)?
Message<1_message: test>