gift_event.go 827 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
package gift_c

import (
	"encoding/json"
	"git.hilo.cn/hilo-common/domain"
	"github.com/go-redis/redis/v8"
	"hilo-group/domain/event/gift_ev"
	"time"
)

const EventSendGiftHiloGroupQueue = "send:gift:queue:hilo_group"

// redis pop event sendGift
func BLPopQueueSendGift(model *domain.Model) *gift_ev.SendGiftEvent {
	var res *gift_ev.SendGiftEvent
	queue := EventSendGiftHiloGroupQueue
hujiebin's avatar
hujiebin committed
17
	strs, err := model.RedisCluster.BLPop(model, time.Second, queue).Result()
hujiebin's avatar
hujiebin committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
	if err != nil {
		if err != redis.Nil {
			model.Log.Errorf("BLPopQueueSendGift fail:%v", err)
		}
		return nil
	}
	if len(strs) >= 2 {
		content := strs[1]
		res = new(gift_ev.SendGiftEvent)
		if err := json.Unmarshal([]byte(content), res); err != nil {
			model.Log.Errorf("BLPopQueueSendGift json fail:%v", err)
			return nil
		}
		return res
	}
	return nil
}