//同步数据到DB服务器
func onSyncDBTimer() {
	debug.Start("SyncDBTimer")
	defer debug.Stop("SyncDBTimer")

	datas := redisProxy.PullDBWriteMsg()
	if datas == nil {
		return
	}
	dlen := len(datas)
	INFO("SyncDB Num: ", dlen)
	for i := 0; i < dlen; i++ {
		serverMsgDispatchAsync.Process(nil, datas[i])
	}
}
Beispiel #2
0
//定时处理用户下线
func (this UserModule) onDealOfflineUserTimer() {
	debug.Start("DealOfflineUserTimer")
	defer debug.Stop("DealOfflineUserTimer")

	users := redisProxy.GetAllUserLastLoginTime()
	INFO("Deal Remove User Redis Cache Data Num:", len(users))

	nowTime := time.Now().Unix()
	delUsers := list.New()
	for userID, lastLoginTime := range users {
		if nowTime >= lastLoginTime+OFFLINEUSER_TIME {
			delUsers.PushBack(userID)
		}
	}

	for tmp := delUsers.Front(); tmp != nil; tmp = tmp.Next() {
		userID, _ := strconv.ParseUint(tmp.Value.(string), 10, 64)
		//超时并且不在线
		if module.Cache.GetOnlineUserByUserID(userID) == nil {
			redisProxy.RemoveDBUser(userID)
		}
	}
	INFO("Remove User Redis Cache Data Num:", delUsers.Len())
}