gift_event.go 816 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
package gift_c

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

const EventSendGiftHiloUserQueue = "send:gift:queue:hilo_user"

// redis pop event sendGift
func BLPopQueueSendGift(model *domain.Model) *gift_ev.SendGiftEvent {
	var res *gift_ev.SendGiftEvent
	queue := EventSendGiftHiloUserQueue
	strs, err := model.Redis.BLPop(model, time.Second, queue).Result()
	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
}