Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
33c8712c72 | ||
|
|
26763c04e3 | ||
|
|
8c60a1f6c7 | ||
|
|
62b0e429b3 | ||
|
|
e1f1bea0e7 | ||
|
|
299ba0b93e | ||
|
|
c12c49477c |
@@ -22,7 +22,7 @@ func Boot() (err error) {
|
|||||||
service.SystemCron().AddCronV2(v1.CronType_HOUR, func(context.Context) error {
|
service.SystemCron().AddCronV2(v1.CronType_HOUR, func(context.Context) error {
|
||||||
go func() {
|
go func() {
|
||||||
err = service.GameKv().SavesV1()
|
err = service.GameKv().SavesV1()
|
||||||
err = service.GameAct().Saves()
|
err = service.GameAct().SavesV2()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Log().Error(gctx.New(), err)
|
g.Log().Error(gctx.New(), err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ayflying/utility_go/internal/model/do"
|
"github.com/ayflying/utility_go/internal/model/do"
|
||||||
@@ -14,6 +15,7 @@ import (
|
|||||||
service2 "github.com/ayflying/utility_go/service"
|
service2 "github.com/ayflying/utility_go/service"
|
||||||
"github.com/ayflying/utility_go/tools"
|
"github.com/ayflying/utility_go/tools"
|
||||||
"github.com/gogf/gf/v2/container/gset"
|
"github.com/gogf/gf/v2/container/gset"
|
||||||
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/os/gctx"
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
"github.com/gogf/gf/v2/os/gtime"
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
@@ -110,6 +112,12 @@ func (s *sGameAct) Set(uid int64, actId int, data interface{}) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Saves 保存游戏活动数据
|
||||||
|
//
|
||||||
|
// @Description: 保存游戏活动数据
|
||||||
|
// @receiver s *sGameAct: 游戏活动服务结构体指针
|
||||||
|
// @return err error: 返回错误信息
|
||||||
|
// Deprecated: 该方法已被弃用,建议使用SavesV2方法
|
||||||
func (s *sGameAct) Saves() (err error) {
|
func (s *sGameAct) Saves() (err error) {
|
||||||
var ctx = gctx.New()
|
var ctx = gctx.New()
|
||||||
g.Log().Debug(ctx, "开始执行游戏act数据保存了")
|
g.Log().Debug(ctx, "开始执行游戏act数据保存了")
|
||||||
@@ -130,12 +138,19 @@ func (s *sGameAct) Saves() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save 保存游戏活动数据
|
||||||
|
//
|
||||||
|
// @Description: 保存游戏活动数据
|
||||||
|
// @receiver s *sGameAct: 游戏活动服务结构体指针
|
||||||
|
// @param ctx context.Context: 上下文对象
|
||||||
|
// @param actId int: 活动ID
|
||||||
|
// @return err error: 返回错误信息
|
||||||
|
// deprecated: 该方法已被弃用,建议使用SaveV2方法
|
||||||
func (s *sGameAct) Save(ctx context.Context, actId int) (err error) {
|
func (s *sGameAct) Save(ctx context.Context, actId int) (err error) {
|
||||||
|
|
||||||
cacheKey := fmt.Sprintf("act:%v:*", actId)
|
cacheKey := fmt.Sprintf("act:%v:*", actId)
|
||||||
var add = make([]*entity.GameAct, 0)
|
var add = make([]*entity.GameAct, 0)
|
||||||
var update = make([]*entity.GameAct, 0)
|
var update = make([]*entity.GameAct, 0)
|
||||||
|
|
||||||
//循环获取缓存数据
|
//循环获取缓存数据
|
||||||
err = tools.Redis.RedisScanV2(cacheKey, func(keys []string) (err error) {
|
err = tools.Redis.RedisScanV2(cacheKey, func(keys []string) (err error) {
|
||||||
//判断是否超时
|
//判断是否超时
|
||||||
@@ -268,8 +283,272 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SavesV2 保存游戏活动数据
|
||||||
|
//
|
||||||
|
// @Description: 保存游戏活动数据
|
||||||
|
// @receiver s *sGameAct: 游戏活动服务结构体指针
|
||||||
|
// @return err error: 返回错误信息
|
||||||
|
// SavesV2 保存游戏活动数据
|
||||||
|
func (s *sGameAct) SavesV2() (err error) {
|
||||||
|
var ctx = gctx.New()
|
||||||
|
g.Log().Debug(ctx, "开始执行游戏act数据保存了")
|
||||||
|
RunTimeMax = gtime.Now().Add(time.Minute * 30)
|
||||||
|
|
||||||
|
// 使用局部通道替代包级通道,避免并发冲突
|
||||||
|
addChan := make(chan *entity.GameAct, 1000)
|
||||||
|
updateChan := make(chan *entity.GameAct, 1000)
|
||||||
|
|
||||||
|
errChan := make(chan error, 1)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(1) // 仅需添加1次(对应Cache2SqlChan协程)
|
||||||
|
// wg.Add(1) // 移除多余的Add调用,避免计数不平衡
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done() // Cache2SqlChan协程完成后减1
|
||||||
|
s.Cache2SqlChan(ctx, addChan, updateChan)
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
scanErr := tools.Redis.RedisScanV2("act:*", func(keys []string) error {
|
||||||
|
if gtime.Now().After(RunTimeMax) {
|
||||||
|
return errors.New("Redis扫描超时")
|
||||||
|
}
|
||||||
|
for _, key := range keys {
|
||||||
|
if keyErr := s.SaveV2(ctx, key, addChan, updateChan); keyErr != nil {
|
||||||
|
g.Log().Errorf(ctx, "处理key %s失败: %v", key, keyErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
close(addChan)
|
||||||
|
close(updateChan)
|
||||||
|
errChan <- scanErr
|
||||||
|
}()
|
||||||
|
|
||||||
|
// 等待扫描和处理完成,同时监听上下文取消
|
||||||
|
select {
|
||||||
|
case scanErr := <-errChan:
|
||||||
|
wg.Wait() // 等待Cache2SqlChan处理完剩余数据
|
||||||
|
if scanErr != nil {
|
||||||
|
return gerror.New(fmt.Sprintf("Redis扫描失败: %v", scanErr))
|
||||||
|
}
|
||||||
|
case <-ctx.Done():
|
||||||
|
wg.Wait()
|
||||||
|
return ctx.Err() // 返回上下文取消原因
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveV2 保存游戏活动数据
|
||||||
|
//
|
||||||
|
// @Description: 保存游戏活动数据
|
||||||
|
// @receiver s *sGameAct: 游戏活动服务结构体指针
|
||||||
|
// @param ctx context.Context: 上下文对象
|
||||||
|
// @param cacheKey string: 缓存键
|
||||||
|
// @param add []*entity.GameAct: 添加数据
|
||||||
|
// @param update []*entity.GameAct: 更新数据
|
||||||
|
// @return err error: 返回错误信息
|
||||||
|
func (s *sGameAct) SaveV2(ctx context.Context, cacheKey string, addChan, updateChan chan *entity.GameAct) (err error) {
|
||||||
|
|
||||||
|
result := strings.Split(cacheKey, ":")
|
||||||
|
actId := gconv.Int(result[1])
|
||||||
|
if actId == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var uid int64
|
||||||
|
uid = gconv.Int64(result[2])
|
||||||
|
if uid == 0 {
|
||||||
|
//跳过为空的用户缓存
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取缓存数据
|
||||||
|
cacheGet, _ := g.Redis().Get(ctx, cacheKey)
|
||||||
|
|
||||||
|
if cacheGet.IsEmpty() {
|
||||||
|
//空数据也不保存
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果有活跃,跳过持久化
|
||||||
|
if getBool, _ := pkg.Cache("redis").
|
||||||
|
Contains(ctx, fmt.Sprintf("act:update:%d", uid)); getBool {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取数据库数据
|
||||||
|
var data *entity.GameAct
|
||||||
|
// 从数据库中查询活动信息
|
||||||
|
err = g.Model(Name).Where(do.GameAct{
|
||||||
|
Uid: uid,
|
||||||
|
ActId: actId,
|
||||||
|
}).Fields("uid,act_id").Scan(&data)
|
||||||
|
if err != nil {
|
||||||
|
g.Log().Errorf(ctx, "当前数据错误: %v", cacheKey)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果没有数据,添加
|
||||||
|
actionData := cacheGet.String()
|
||||||
|
if data == nil {
|
||||||
|
//add = append(add, &entity.GameAct{
|
||||||
|
// ActId: actId,
|
||||||
|
// Uid: uid,
|
||||||
|
// Action: actionData,
|
||||||
|
//})
|
||||||
|
addChan <- &entity.GameAct{
|
||||||
|
ActId: actId,
|
||||||
|
Uid: uid,
|
||||||
|
Action: actionData,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//覆盖数据
|
||||||
|
data.ActId = actId
|
||||||
|
data.Uid = uid
|
||||||
|
data.Action = actionData
|
||||||
|
//update = append(update, data)
|
||||||
|
updateChan <- data
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache2Sql 缓存持久化到数据库
|
||||||
|
// @Description: 缓存持久化到数据库
|
||||||
|
// @receiver s *sGameAct: 游戏活动服务结构体指针
|
||||||
|
// @param ctx context.Context: 上下文对象
|
||||||
|
// @param add []*entity.GameAct: 添加数据
|
||||||
|
// @param update []*entity.GameAct: 更新数据
|
||||||
|
// @return err error: 返回错误信息
|
||||||
|
func (s *sGameAct) Cache2Sql(ctx context.Context, add, update []*entity.GameAct) {
|
||||||
|
//批量写入数据库
|
||||||
|
updateCount := 0
|
||||||
|
if len(update) > 0 {
|
||||||
|
for _, v := range update {
|
||||||
|
v.UpdatedAt = gtime.Now()
|
||||||
|
updateRes, err2 := g.Model(Name).Where(do.GameAct{
|
||||||
|
Uid: v.Uid,
|
||||||
|
ActId: v.ActId,
|
||||||
|
}).Data(v).Update()
|
||||||
|
if err2 != nil {
|
||||||
|
g.Log().Error(ctx, err2)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if row, _ := updateRes.RowsAffected(); row == 0 {
|
||||||
|
g.Log().Error(ctx, "本次更新为0,更新数据失败: %v", v)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//删除缓存
|
||||||
|
s.DelCacheKey(ctx, v.ActId, v.Uid)
|
||||||
|
updateCount++
|
||||||
|
}
|
||||||
|
g.Log().Debugf(ctx, "act当前更新数据库: %v 条", updateCount)
|
||||||
|
update = (update)[:0]
|
||||||
|
}
|
||||||
|
|
||||||
|
var addCount int64
|
||||||
|
if len(add) > 0 {
|
||||||
|
for _, v := range add {
|
||||||
|
addRes, err2 := g.Model(Name).Data(v).Insert()
|
||||||
|
if err2 != nil {
|
||||||
|
g.Log().Error(ctx, err2)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if row, _ := addRes.RowsAffected(); row == 0 {
|
||||||
|
g.Log().Error(ctx, "本次新增为0,新增数据失败: %v", v)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
addCount++
|
||||||
|
//删除缓存
|
||||||
|
s.DelCacheKey(ctx, v.ActId, v.Uid)
|
||||||
|
}
|
||||||
|
g.Log().Debugf(ctx, "act当前写入数据库: %v 条", addCount)
|
||||||
|
add = (add)[:0]
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache2AddChan 批量添加数据库
|
||||||
|
func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan *entity.GameAct) {
|
||||||
|
//批量写入数据库计数
|
||||||
|
var addCount int64
|
||||||
|
//批量更新数据库计数
|
||||||
|
var updateCount int64
|
||||||
|
//通道关闭标志
|
||||||
|
addClosed := false
|
||||||
|
updateClosed := false
|
||||||
|
|
||||||
|
// 使用链式安全模式
|
||||||
|
var db = g.Model(Name).Safe()
|
||||||
|
|
||||||
|
for {
|
||||||
|
//检查是否两个通道都已关闭且为空
|
||||||
|
if addClosed && updateClosed {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case v, ok := <-addChan:
|
||||||
|
if !ok {
|
||||||
|
addClosed = true // 仅标记关闭,不立即日志
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
addRes, err2 := db.Data(v).Insert()
|
||||||
|
if err2 != nil {
|
||||||
|
g.Log().Error(ctx, err2)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//if row, _ := addRes.RowsAffected(); row == 0 {
|
||||||
|
// g.Log().Error(ctx, "本次新增为0,新增数据失败: %v", v)
|
||||||
|
// continue
|
||||||
|
//}
|
||||||
|
row, _ := addRes.RowsAffected()
|
||||||
|
addCount += row
|
||||||
|
//删除缓存
|
||||||
|
s.DelCacheKey(ctx, v.ActId, v.Uid)
|
||||||
|
|
||||||
|
case v, ok := <-updateChan:
|
||||||
|
if !ok {
|
||||||
|
updateClosed = true // 仅标记关闭,不立即日志
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
v.UpdatedAt = gtime.Now()
|
||||||
|
updateRes, err2 := db.Where(do.GameAct{
|
||||||
|
Uid: v.Uid,
|
||||||
|
ActId: v.ActId,
|
||||||
|
}).Data(v).Update()
|
||||||
|
if err2 != nil {
|
||||||
|
g.Log().Error(ctx, err2)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if row, _ := updateRes.RowsAffected(); row == 0 {
|
||||||
|
//g.Log().Error(ctx, "本次更新为0,更新数据失败: %v", v)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//删除缓存
|
||||||
|
s.DelCacheKey(ctx, v.ActId, v.Uid)
|
||||||
|
updateCount++
|
||||||
|
|
||||||
|
case <-ctx.Done():
|
||||||
|
g.Log().Debug(ctx, "act协程被上下文取消")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 仅在所有通道处理完毕后打印最终计数(移除中间冗余日志)
|
||||||
|
g.Log().Debugf(ctx, "act当前写入数据库: %v 条", addCount)
|
||||||
|
g.Log().Debugf(ctx, "act当前更新数据库: %v 条", updateCount)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 删除缓存key
|
// 删除缓存key
|
||||||
func (s *sGameAct) DelCacheKey(ctx context.Context, aid int, uid int64) {
|
func (s *sGameAct) DelCacheKey(ctx context.Context, aid int, uid int64) {
|
||||||
|
//如果有活跃,跳过删除
|
||||||
|
if getBool, _ := pkg.Cache("redis").
|
||||||
|
Contains(ctx, fmt.Sprintf("act:update:%d", uid)); getBool {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
cacheKey := fmt.Sprintf("act:%v:%v", aid, uid)
|
cacheKey := fmt.Sprintf("act:%v:%v", aid, uid)
|
||||||
_, err := g.Redis().Del(ctx, cacheKey)
|
_, err := g.Redis().Del(ctx, cacheKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -15,6 +14,7 @@ import (
|
|||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/os/gctx"
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
"github.com/gogf/gf/v2/os/gtime"
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -72,19 +72,17 @@ func (s *sGameKv) SavesV1() (err error) {
|
|||||||
//uid := v.Int64()
|
//uid := v.Int64()
|
||||||
//cacheKey = "user:kv:" + strconv.FormatInt(uid, 10)
|
//cacheKey = "user:kv:" + strconv.FormatInt(uid, 10)
|
||||||
result := strings.Split(cacheKey, ":")
|
result := strings.Split(cacheKey, ":")
|
||||||
var uid int64
|
var uid = gconv.Int64(result[2])
|
||||||
uid, err = strconv.ParseInt(result[2], 10, 64)
|
if uid == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//uid, err = strconv.ParseInt(result[2], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Log().Error(ctx, err)
|
g.Log().Error(ctx, err)
|
||||||
g.Redis().Del(ctx, cacheKey)
|
g.Redis().Del(ctx, cacheKey)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
////如果1天没有活跃,跳过
|
|
||||||
//user, _ := service.MemberUser().Info(uid)
|
|
||||||
//if user.UpdatedAt.Seconds < gtime.Now().Add(consts.ActSaveTime).Unix() {
|
|
||||||
// continue
|
|
||||||
//}
|
|
||||||
//如果有活跃,跳过持久化
|
//如果有活跃,跳过持久化
|
||||||
if getBool, _ := pkg.Cache("redis").
|
if getBool, _ := pkg.Cache("redis").
|
||||||
Contains(ctx, fmt.Sprintf("act:update:%d", uid)); getBool {
|
Contains(ctx, fmt.Sprintf("act:update:%d", uid)); getBool {
|
||||||
@@ -94,6 +92,9 @@ func (s *sGameKv) SavesV1() (err error) {
|
|||||||
get, _ := g.Redis().Get(ctx, cacheKey)
|
get, _ := g.Redis().Get(ctx, cacheKey)
|
||||||
var data interface{}
|
var data interface{}
|
||||||
get.Scan(&data)
|
get.Scan(&data)
|
||||||
|
if data == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
list = append(list, &ListData{
|
list = append(list, &ListData{
|
||||||
Uid: uid,
|
Uid: uid,
|
||||||
Kv: data,
|
Kv: data,
|
||||||
@@ -103,21 +104,17 @@ func (s *sGameKv) SavesV1() (err error) {
|
|||||||
// 将列表数据保存到数据库
|
// 将列表数据保存到数据库
|
||||||
if len(list) > 100 {
|
if len(list) > 100 {
|
||||||
_, err2 := g.Model("game_kv").Data(list).Save()
|
_, err2 := g.Model("game_kv").Data(list).Save()
|
||||||
|
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
g.Log().Error(ctx, err2)
|
g.Log().Error(ctx, "当前kv数据入库失败: %v", err2)
|
||||||
|
err = err2
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//删除当前key
|
//删除当前key
|
||||||
for _, v := range list {
|
for _, v := range list {
|
||||||
go s.DelCacheKey(ctx, v.Uid)
|
s.DelCacheKey(ctx, v.Uid)
|
||||||
}
|
}
|
||||||
list = make([]*ListData, 0)
|
list = make([]*ListData, 0)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
g.Log().Error(ctx, "当前kv数据入库失败: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -126,6 +123,12 @@ func (s *sGameKv) SavesV1() (err error) {
|
|||||||
|
|
||||||
// 删除缓存key
|
// 删除缓存key
|
||||||
func (s *sGameKv) DelCacheKey(ctx context.Context, uid int64) {
|
func (s *sGameKv) DelCacheKey(ctx context.Context, uid int64) {
|
||||||
|
//如果有活跃,跳过删除
|
||||||
|
if getBool, _ := pkg.Cache("redis").
|
||||||
|
Contains(ctx, fmt.Sprintf("act:update:%d", uid)); getBool {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
cacheKey := fmt.Sprintf("user:kv:%v", uid)
|
cacheKey := fmt.Sprintf("user:kv:%v", uid)
|
||||||
_, err := g.Redis().Del(ctx, cacheKey)
|
_, err := g.Redis().Del(ctx, cacheKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/ayflying/utility_go/internal/model/entity"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,8 +32,48 @@ type (
|
|||||||
// @param data interface{}: 要存储的活动信息数据。
|
// @param data interface{}: 要存储的活动信息数据。
|
||||||
// @return err error: 返回错误信息,如果操作成功,则返回nil。
|
// @return err error: 返回错误信息,如果操作成功,则返回nil。
|
||||||
Set(uid int64, actId int, data interface{}) (err error)
|
Set(uid int64, actId int, data interface{}) (err error)
|
||||||
|
// Saves 保存游戏活动数据
|
||||||
|
//
|
||||||
|
// @Description: 保存游戏活动数据
|
||||||
|
// @receiver s *sGameAct: 游戏活动服务结构体指针
|
||||||
|
// @return err error: 返回错误信息
|
||||||
|
// Deprecated: 该方法已被弃用,建议使用SavesV2方法
|
||||||
Saves() (err error)
|
Saves() (err error)
|
||||||
|
// Save 保存游戏活动数据
|
||||||
|
//
|
||||||
|
// @Description: 保存游戏活动数据
|
||||||
|
// @receiver s *sGameAct: 游戏活动服务结构体指针
|
||||||
|
// @param ctx context.Context: 上下文对象
|
||||||
|
// @param actId int: 活动ID
|
||||||
|
// @return err error: 返回错误信息
|
||||||
|
// deprecated: 该方法已被弃用,建议使用SaveV2方法
|
||||||
Save(ctx context.Context, actId int) (err error)
|
Save(ctx context.Context, actId int) (err error)
|
||||||
|
// SavesV2 保存游戏活动数据
|
||||||
|
//
|
||||||
|
// @Description: 保存游戏活动数据
|
||||||
|
// @receiver s *sGameAct: 游戏活动服务结构体指针
|
||||||
|
// @return err error: 返回错误信息
|
||||||
|
SavesV2() (err error)
|
||||||
|
// SaveV2 保存游戏活动数据
|
||||||
|
//
|
||||||
|
// @Description: 保存游戏活动数据
|
||||||
|
// @receiver s *sGameAct: 游戏活动服务结构体指针
|
||||||
|
// @param ctx context.Context: 上下文对象
|
||||||
|
// @param cacheKey string: 缓存键
|
||||||
|
// @param add []*entity.GameAct: 添加数据
|
||||||
|
// @param update []*entity.GameAct: 更新数据
|
||||||
|
// @return err error: 返回错误信息
|
||||||
|
SaveV2(ctx context.Context, cacheKey string, addChan chan *entity.GameAct, updateChan chan *entity.GameAct) (err error)
|
||||||
|
// Cache2Sql 缓存持久化到数据库
|
||||||
|
// @Description: 缓存持久化到数据库
|
||||||
|
// @receiver s *sGameAct: 游戏活动服务结构体指针
|
||||||
|
// @param ctx context.Context: 上下文对象
|
||||||
|
// @param add []*entity.GameAct: 添加数据
|
||||||
|
// @param update []*entity.GameAct: 更新数据
|
||||||
|
// @return err error: 返回错误信息
|
||||||
|
Cache2Sql(ctx context.Context, add []*entity.GameAct, update []*entity.GameAct)
|
||||||
|
// Cache2AddChan 批量添加数据库
|
||||||
|
Cache2SqlChan(ctx context.Context, addChan chan *entity.GameAct, updateChan chan *entity.GameAct)
|
||||||
// 删除缓存key
|
// 删除缓存key
|
||||||
DelCacheKey(ctx context.Context, aid int, uid int64)
|
DelCacheKey(ctx context.Context, aid int, uid int64)
|
||||||
// 清空GetRedDot缓存
|
// 清空GetRedDot缓存
|
||||||
|
|||||||
Reference in New Issue
Block a user