mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-09 17:30:25 +08:00
feat: 机器列表新增运行状态 & refactor: 登录账号信息存储与context
This commit is contained in:
24
server/internal/machine/infrastructure/cache/machine_stats.go
vendored
Normal file
24
server/internal/machine/infrastructure/cache/machine_stats.go
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"mayfly-go/internal/machine/mcm"
|
||||
global_cache "mayfly-go/pkg/cache"
|
||||
"mayfly-go/pkg/utils/jsonx"
|
||||
"time"
|
||||
)
|
||||
|
||||
const MachineStatCackeKey = "mayfly:machine:%d:stat"
|
||||
|
||||
func SaveMachineStats(machineId uint64, stat *mcm.Stats) error {
|
||||
return global_cache.SetStr(fmt.Sprintf(MachineStatCackeKey, machineId), jsonx.ToStr(stat), 10*time.Minute)
|
||||
}
|
||||
|
||||
func GetMachineStats(machineId uint64) (*mcm.Stats, error) {
|
||||
cacheStr := global_cache.GetStr(fmt.Sprintf(MachineStatCackeKey, machineId))
|
||||
if cacheStr == "" {
|
||||
return nil, errors.New("不存在该值")
|
||||
}
|
||||
return jsonx.To(cacheStr, new(mcm.Stats))
|
||||
}
|
||||
Reference in New Issue
Block a user