You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paopao-ce/internal/servants/chain/metrics.go

37 lines
845 B

// Copyright 2023 ROC. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package chain
import (
"github.com/rocboss/paopao-ce/internal/conf"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/metrics"
)
type OnlineUserMetric struct {
metrics.BaseMetric
ac core.AppCache
uid int64
expire int64
}
func OnUserOnlineMetric(ac core.AppCache, uid int64) {
metrics.OnMeasure(&OnlineUserMetric{
ac: ac,
uid: uid,
expire: conf.CacheSetting.OnlineUserExpire,
})
}
func (m *OnlineUserMetric) Name() string {
return "OnlineUserMetric"
}
func (m *OnlineUserMetric) Action() (err error) {
// 暂时仅做标记,不存储其他相关信息
m.ac.SetNx(conf.KeyOnlineUser.Get(m.uid), []byte{}, m.expire)
return
}