funcmain() { var mu sync.RWMutex var items = make(map[string][]byte) var ps redcon.PubSub go log.Printf("started server at %s", addr) err := redcon.ListenAndServe(addr, func(conn redcon.Conn, cmd redcon.Command) { // 参数处理逻辑 switch strings.ToLower(string(cmd.Args[0])) { default: conn.WriteError("ERR unknown command '" + string(cmd.Args[0]) + "'") case"ping": conn.WriteString("PONG") case"quit": conn.WriteString("OK") conn.Close() }, // 设置标志位,置1 拒绝连接接入 func(conn redcon.Conn)bool { // Use this function to accept or deny the connection. // log.Printf("accept: %s", conn.RemoteAddr()) returntrue }, // close时,清除Kafka相关资源 func(conn redcon.Conn, err error) { // This is called when the connection has been closed // log.Printf("closed: %s, err: %v", conn.RemoteAddr(), err) }, ) if err != nil { log.Fatal(err) } }