D
D
ddddd tttt2019-06-09 17:32:44
go
ddddd tttt, 2019-06-09 17:32:44

How to get test message?

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 returns a message in this format. How to get the message (test)?
Message<1_message:test>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question