Exemplo n.º 1
0
// 向队列中添加消息
func (this *OfflineTopicQueue) Add(msg_bytes []byte) {
	this.lock.Lock()
	defer this.lock.Unlock()
	if this.Q == nil && MessageQueueStore == "local" {
		this.Q = make([][]byte, Max_message_queue, Max_message_queue)
	}

	switch MessageQueueStore {
	case "local":
		this.Q[this.Pos] = msg_bytes
	case "redis":
		_, err := topics.RedisDo("set", this.DBKey(this.Pos), msg_bytes)
		if err != nil {
			Log.Errorc(func() string {
				return fmt.Sprintf("failed to save offline msg to redis: %s", err.Error())
			})
		}
	case "leveldb":
		err := LevelDB.Put([]byte(this.DBKey(this.Pos)), msg_bytes, nil)
		if err != nil {
			Log.Error("leveldb: %s", err.Error())
		}
	}

	this.Pos++

	if this.Pos >= Max_message_queue {
		this.Pos = 0
	}

	if this.Cleaned {
		this.Cleaned = false
	}
}
Exemplo n.º 2
0
// 处理苹果设备的未读数,修改redis
func (this *service) processBadge(account_id string, badge_message *BadgeMessage) {
	key := "badge_account:" + account_id
	_, err := topics.RedisDo("set", key, badge_message.Data)
	if err != nil {
		Log.Errorc(func() string {
			return fmt.Sprintf("(%s) can't set badge! account_id: %s, badge: %v", this.cid(), account_id, badge_message)
		})
	}
}