| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package main
- import (
- "fmt"
- "github.com/gomodule/redigo/redis"
- "reflect"
- //"github.com/vmihailenco/msgpack/v5"
- )
- // dial wraps DialDefaultServer() with a more suitable function name for examples.
- func dial() (redis.Conn, error) {
- c, err := redis.Dial("tcp", "127.0.0.1:11001")
- if err != nil {
- return nil ,err
- }
- return c, nil
- }
- func main() {
- c, err := dial()
- if err != nil {
- fmt.Println(err)
- return
- }
- defer c.Close()
-
- //c.Send("SUBSCRIBE", "example")
- c.Send("SUBSCRIBE", "CLASS_DATA_CHANGE:/matrix/devops/@matrix")
- c.Flush()
-
- count := 0
- for {
- count++
- reply, err := c.Receive()
- if err != nil {
- fmt.Printf("err: %v", err)
- }else{
- switch data := reply.(type) {
- case string : fmt.Printf("reply: %s", data)
- case int : fmt.Printf("reply: %d", data)
- case []interface {} :
- fmt.Printf("reply: ")
- for _, item := range data {
- switch v := item.(type) {
- case string : fmt.Printf(" %s ", v)
- case []uint8: fmt.Printf(" %s ", string(v))
- case int64 : fmt.Printf(" %d ", v)
- case int : fmt.Printf(" %d ", v)
- default : fmt.Printf("type: %v", reflect.TypeOf(item))
- }
- }
- fmt.Printf("\n")
- default : fmt.Printf("type: %v", reflect.TypeOf(reply))
- }
- }
-
- if count == 2 {
- break
- }
- // process pushed message
- }
-
- //c.Send("UNSUBSCRIBE", "CLASS_DATA_CHANGE:/matrix/devops/change@matrix")
- c.Send("quit")
- c.Flush()
-
- }
|