Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27435b57b7 | ||
|
|
0628882533 | ||
|
|
f68655eee6 | ||
|
|
d8491f0aba |
@@ -3,6 +3,10 @@ package gameAct
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ayflying/utility_go/internal/model/do"
|
"github.com/ayflying/utility_go/internal/model/do"
|
||||||
"github.com/ayflying/utility_go/internal/model/entity"
|
"github.com/ayflying/utility_go/internal/model/entity"
|
||||||
"github.com/ayflying/utility_go/pkg"
|
"github.com/ayflying/utility_go/pkg"
|
||||||
@@ -13,9 +17,6 @@ import (
|
|||||||
"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"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -206,37 +207,29 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) {
|
|||||||
g.Log().Error(ctx, err2)
|
g.Log().Error(ctx, err2)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
////获取多少个数据,删除不是当前修改的数据
|
|
||||||
//count, _ := g.Model(Name).Where(do.GameAct{
|
|
||||||
// Uid: v.Uid,
|
|
||||||
// ActId: v.ActId,
|
|
||||||
//}).Count()
|
|
||||||
//if count > 1 {
|
|
||||||
// g.Model(Name).Where(do.GameAct{
|
|
||||||
// Uid: v.Uid,
|
|
||||||
// ActId: v.ActId,
|
|
||||||
// }).WhereNot("updated_at", v.UpdatedAt).Delete()
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
//dbRes, err2 := g.Model(Name).Batch(50).Data(add).Update()
|
|
||||||
update = make([]*entity.GameAct, 0)
|
update = make([]*entity.GameAct, 0)
|
||||||
dbRes, err2 := g.Model(Name).Batch(50).Data(add).Save()
|
var count int64
|
||||||
add = make([]*entity.GameAct, 0)
|
|
||||||
if err2 != nil {
|
if len(add) > 0 {
|
||||||
g.Log().Error(ctx, err2)
|
dbRes, err2 := g.Model(Name).Batch(50).Data(add).Save()
|
||||||
return
|
add = make([]*entity.GameAct, 0)
|
||||||
|
err = err2
|
||||||
|
if err != nil {
|
||||||
|
g.Log().Error(ctx, err2)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
count, _ = dbRes.RowsAffected()
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range delKey {
|
for _, v := range delKey {
|
||||||
_, err2 = g.Redis().Del(ctx, v)
|
_, err = g.Redis().Del(ctx, v)
|
||||||
if err2 != nil {
|
if err != nil {
|
||||||
g.Log().Error(ctx, err2)
|
g.Log().Error(ctx, err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delKey = make([]string, 0)
|
delKey = make([]string, 0)
|
||||||
|
|
||||||
count, _ := dbRes.RowsAffected()
|
|
||||||
g.Log().Debugf(ctx, "当前 %v 写入数据库: %v 条", actId, count)
|
g.Log().Debugf(ctx, "当前 %v 写入数据库: %v 条", actId, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,17 @@ package gameKv
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ayflying/utility_go/pkg"
|
"github.com/ayflying/utility_go/pkg"
|
||||||
"github.com/ayflying/utility_go/service"
|
"github.com/ayflying/utility_go/service"
|
||||||
"github.com/ayflying/utility_go/tools"
|
"github.com/ayflying/utility_go/tools"
|
||||||
"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"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -107,8 +108,7 @@ func (s *sGameKv) SavesV1() (err error) {
|
|||||||
for _, v := range delKey {
|
for _, v := range delKey {
|
||||||
_, err2 = g.Redis().Del(ctx, v)
|
_, err2 = g.Redis().Del(ctx, v)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
g.Log().Errorf(ctx, "删除存档错误:%v,err=%v", v, err2)
|
g.Log().Errorf(ctx, "删除存档失败:%v,err=%v", v, err2)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package ip2region
|
package ip2region
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/ayflying/utility_go/service"
|
"github.com/ayflying/utility_go/service"
|
||||||
"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/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
||||||
"net"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -81,7 +82,7 @@ func (s *sIp2region) Load() {
|
|||||||
|
|
||||||
func (s *sIp2region) GetIp(ip string) (res []string) {
|
func (s *sIp2region) GetIp(ip string) (res []string) {
|
||||||
//初始化加载
|
//初始化加载
|
||||||
if s.searcher != nil {
|
if s.searcher == nil {
|
||||||
s.Load()
|
s.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package aycache
|
package aycache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
v1 "github.com/ayflying/utility_go/api/system/v1"
|
v1 "github.com/ayflying/utility_go/api/system/v1"
|
||||||
"github.com/ayflying/utility_go/internal/boot"
|
"github.com/ayflying/utility_go/internal/boot"
|
||||||
"github.com/ayflying/utility_go/pkg/aycache/drive"
|
"github.com/ayflying/utility_go/pkg/aycache/drive"
|
||||||
@@ -9,7 +11,6 @@ import (
|
|||||||
"github.com/gogf/gf/v2/os/gcache"
|
"github.com/gogf/gf/v2/os/gcache"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
"math"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Mod 定义缓存模块结构体,包含一个 gcache.Cache 客户端实例
|
// Mod 定义缓存模块结构体,包含一个 gcache.Cache 客户端实例
|
||||||
@@ -19,6 +20,7 @@ type Mod struct {
|
|||||||
|
|
||||||
// QPSCount 记录缓存的 QPS 计数
|
// QPSCount 记录缓存的 QPS 计数
|
||||||
var QPSCount int
|
var QPSCount int
|
||||||
|
|
||||||
// QPS 是一个 Prometheus 指标,用于记录当前缓存的 QPS 数量
|
// QPS 是一个 Prometheus 指标,用于记录当前缓存的 QPS 数量
|
||||||
var QPS = promauto.NewGauge(
|
var QPS = promauto.NewGauge(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
@@ -53,8 +55,13 @@ func New(_name ...string) gcache.Adapter {
|
|||||||
// 创建内存缓存适配器
|
// 创建内存缓存适配器
|
||||||
cacheAdapterObj = drive2.NewAdapterMemory()
|
cacheAdapterObj = drive2.NewAdapterMemory()
|
||||||
case "redis":
|
case "redis":
|
||||||
|
//第二个参数为配置名称,默认为default
|
||||||
|
var typ = "default"
|
||||||
|
if len(_name) >= 2 {
|
||||||
|
typ = _name[1]
|
||||||
|
}
|
||||||
// 创建 Redis 缓存适配器
|
// 创建 Redis 缓存适配器
|
||||||
cacheAdapterObj = drive2.NewAdapterRedis()
|
cacheAdapterObj = drive2.NewAdapterRedis(typ)
|
||||||
case "file":
|
case "file":
|
||||||
// 创建文件缓存适配器,指定缓存目录为 "runtime/cache"
|
// 创建文件缓存适配器,指定缓存目录为 "runtime/cache"
|
||||||
cacheAdapterObj = drive2.NewAdapterFile("runtime/cache")
|
cacheAdapterObj = drive2.NewAdapterFile("runtime/cache")
|
||||||
|
|||||||
@@ -7,19 +7,22 @@ import (
|
|||||||
"github.com/gogf/gf/v2/os/gctx"
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
)
|
)
|
||||||
|
|
||||||
var adapterRedisClient gcache.Adapter
|
var adapterRedisClient = make(map[string]gcache.Adapter)
|
||||||
var adapterRedisCache = gcache.New()
|
var adapterRedisCache = make(map[string]*gcache.Cache)
|
||||||
|
|
||||||
func NewAdapterRedis() gcache.Adapter {
|
func NewAdapterRedis(name string) gcache.Adapter {
|
||||||
|
if adapterRedisClient[name] == nil {
|
||||||
if adapterRedisClient == nil {
|
_cfg, err := g.Cfg().Get(gctx.New(), "redis."+name)
|
||||||
_cfg, _ := g.Cfg().Get(gctx.New(), "redis.default")
|
if err != nil {
|
||||||
|
panic("当前redis配置不存在")
|
||||||
|
}
|
||||||
var cfg *gredis.Config
|
var cfg *gredis.Config
|
||||||
_cfg.Scan(&cfg)
|
_cfg.Scan(&cfg)
|
||||||
redisObj, _ := gredis.New(cfg)
|
redisObj, _ := gredis.New(cfg)
|
||||||
//adapterRedisClient = gcache.NewAdapterRedis(g.Redis("default"))
|
//adapterRedisClient[name] = gcache.NewAdapterRedis(g.Redis(name))
|
||||||
adapterRedisClient = gcache.NewAdapterRedis(redisObj)
|
adapterRedisClient[name] = gcache.NewAdapterRedis(redisObj)
|
||||||
adapterRedisCache.SetAdapter(adapterRedisClient)
|
adapterRedisCache[name] = gcache.New()
|
||||||
|
adapterRedisCache[name].SetAdapter(adapterRedisClient[name])
|
||||||
}
|
}
|
||||||
return adapterRedisCache
|
return adapterRedisCache[name]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user