Exemple #1
0
func (r *RedisClient) Emit(in *apipb.EmitRequest) {
	data, err := in.Marshal()
	if err != nil {
		logrus.Errorf("failed to marshall request error=%+v", err)
		return
	}
	if err := r.client.Publish(channelName, base64.StdEncoding.EncodeToString(data)).Err(); err != nil {
		logrus.Errorf("failed to publish emitrequest, %+v", err)
	}
}
Exemple #2
0
func (r *RedisClient) Receive() {
	for {
		mes, err := r.pubsub.ReceiveMessage()
		if err != nil {
			logrus.Errorf("Failed to receive message, error=%+v", err)
			continue
		}
		data, err := base64.StdEncoding.DecodeString(mes.Payload)
		if err != nil {
			logrus.Errorf("Failed to receive message, error=%+v", err)
			continue
		}
		req := apipb.EmitRequest{}
		err = req.Unmarshal(data)
		if err != nil {
			logrus.Errorf("Failed to Unmarshal byte data")
			continue
		}
		h.broadcast <- &req
	}
}