package log import ( "context" "log-server/global" ) type Computer struct { Id uint `json:"id"` PcCode string `json:"pc_code"` User string `json:"user"` Status int `json:"status"` CreateTime string `json:"create_time"` // 创建时间 UpdateTime string `json:"update_time"` // 更新时间 Supplier string `json:"supplier"` //电脑供应商 } func (Computer) TableName() string { return "computer" } const OnlinePcCode = "Online:PcCode" func (c *Computer) OnlinePcCodeCache() (mps map[string]string, err error) { ctx := context.Background() isNull, _ := global.GVA_REDIS.Exists(ctx, OnlinePcCode).Result() if isNull != 0 { mps, err = global.GVA_REDIS.HGetAll(ctx, OnlinePcCode).Result() return } return } // 更新单条缓存数据 func (c *Computer) UpdateOnlinePcCodeCache(pcCode, user string) (err error) { ctx := context.Background() err = global.GVA_REDIS.HSet(ctx, OnlinePcCode, pcCode, user).Err() return } // 删除单条缓存数据 func (c *Computer) DelOnlinePcCodeCache(pcCode string) (err error) { ctx := context.Background() err = global.GVA_REDIS.HDel(ctx, OnlinePcCode, pcCode).Err() return } // 清空缓存数据 func (c *Computer) DelAllOnlinePcCodeCache() (err error) { ctx := context.Background() keys, _ := global.GVA_REDIS.HKeys(ctx, OnlinePcCode).Result() err = global.GVA_REDIS.HDel(ctx, OnlinePcCode, keys...).Err() return } func (c *Computer) ExistsPcCodeCache(pcCode string) bool { ctx := context.Background() b, _ := global.GVA_REDIS.HExists(ctx, OnlinePcCode, pcCode).Result() return b }