From 3455fb0a1cf74cac1c2c84debceff856eb5b609c Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Thu, 22 Jan 2026 02:44:53 +0800 Subject: [PATCH] =?UTF-8?q?style(cache):=20=E6=A0=BC=E5=BC=8F=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=B3=A8=E9=87=8A=E4=B8=AD=E7=9A=84=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=E5=B9=B6=E6=B7=BB=E5=8A=A0=20DISTINCT=20=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复了缓存相关文件中注释开头缺少空格的问题 - 在 db/hotimedb.go 中为 vcond 数组添加了 "DISTINCT" 选项 - 注释掉了 session.go 中的并发控制代码以简化实现 --- cache/cache.go | 2 +- cache/cache_db.go | 4 ++-- cache/cache_redis.go | 4 ++-- cache/type.go | 2 +- common/context_base.go | 2 +- common/func.go | 2 +- context.go | 2 +- db/hotimedb.go | 2 +- dri/ddsms/ddsms.go | 4 ++-- dri/wechat/h5program.go | 4 ++-- dri/wechat/pay.go | 4 ++-- manage/manage.go | 4 ++-- session.go | 9 ++++++++- 13 files changed, 26 insertions(+), 19 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 1462518..28b2626 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -6,7 +6,7 @@ import ( ) // HoTimeCache 可配置memory,db,redis,默认启用memory,默认优先级为memory>redis>db,memory与数据库缓存设置项一致, -//缓存数据填充会自动反方向反哺,加入memory缓存过期将自动从redis更新,但memory永远不会更新redis,如果是集群建议不要开启memory,配置即启用 +// 缓存数据填充会自动反方向反哺,加入memory缓存过期将自动从redis更新,但memory永远不会更新redis,如果是集群建议不要开启memory,配置即启用 type HoTimeCache struct { *Error dbCache *CacheDb diff --git a/cache/cache_db.go b/cache/cache_db.go index f0c2a49..958c210 100644 --- a/cache/cache_db.go +++ b/cache/cache_db.go @@ -87,7 +87,7 @@ func (that *CacheDb) initDbTable() { } -//获取Cache键只能为string类型 +// 获取Cache键只能为string类型 func (that *CacheDb) get(key string) interface{} { cached := that.Db.Get("cached", "*", Map{"key": key}) @@ -108,7 +108,7 @@ func (that *CacheDb) get(key string) interface{} { return data.Get("data") } -//key value ,时间为时间戳 +// key value ,时间为时间戳 func (that *CacheDb) set(key string, value interface{}, tim int64) { bte, _ := json.Marshal(Map{"data": value}) diff --git a/cache/cache_redis.go b/cache/cache_redis.go index d62a702..62adb6a 100644 --- a/cache/cache_redis.go +++ b/cache/cache_redis.go @@ -30,7 +30,7 @@ func (that *CacheRedis) SetError(err *Error) { that.Error = err } -//唯一标志 +// 唯一标志 func (that *CacheRedis) GetTag() int64 { if that.tag == int64(0) { @@ -85,7 +85,7 @@ func (that *CacheRedis) del(key string) { } } -//key value ,时间为时间戳 +// key value ,时间为时间戳 func (that *CacheRedis) set(key string, value string, time int64) { _, err := that.conn.Do("SET", key, value, "EX", ObjToStr(time)) if err != nil { diff --git a/cache/type.go b/cache/type.go index e7e69f1..735e933 100644 --- a/cache/type.go +++ b/cache/type.go @@ -13,7 +13,7 @@ type CacheIns interface { Cache(key string, data ...interface{}) *Obj } -//单条缓存数据 +// 单条缓存数据 type cacheData struct { time int64 data interface{} diff --git a/common/context_base.go b/common/context_base.go index 0a4667f..5786cd5 100644 --- a/common/context_base.go +++ b/common/context_base.go @@ -8,7 +8,7 @@ type ContextBase struct { tag string } -//唯一标志 +// 唯一标志 func (that *ContextBase) GetTag() string { if that.tag == "" { diff --git a/common/func.go b/common/func.go index b043cee..5cb9941 100644 --- a/common/func.go +++ b/common/func.go @@ -141,7 +141,7 @@ func Substr(str string, start int, length int) string { } // IndexLastStr 获取最后出现字符串的下标 -//return 找不到返回 -1 +// return 找不到返回 -1 func IndexLastStr(str, sep string) int { sepSlice := []rune(sep) strSlice := []rune(str) diff --git a/context.go b/context.go index df14cd7..19f4953 100644 --- a/context.go +++ b/context.go @@ -33,7 +33,7 @@ func (that *Context) Mtd(router [3]string) Map { return d } -//打印 +// 打印 func (that *Context) Display(statu int, data interface{}) { resp := Map{"status": statu} diff --git a/db/hotimedb.go b/db/hotimedb.go index b5272d8..8dbe554 100644 --- a/db/hotimedb.go +++ b/db/hotimedb.go @@ -891,7 +891,7 @@ func (that *HoTimeDB) Count(table string, qu ...interface{}) int { } var condition = []string{"AND", "OR"} -var vcond = []string{"GROUP", "ORDER", "LIMIT"} +var vcond = []string{"GROUP", "ORDER", "LIMIT", "DISTINCT"} // Count 计数 func (that *HoTimeDB) Sum(table string, column string, qu ...interface{}) float64 { diff --git a/dri/ddsms/ddsms.go b/dri/ddsms/ddsms.go index 5310b25..057fb60 100644 --- a/dri/ddsms/ddsms.go +++ b/dri/ddsms/ddsms.go @@ -49,7 +49,7 @@ func (that *dingdongyun) SendTz(umoblie []string, tpt string, data map[string]st return that.send(that.TzUrl, umobleStr, tpt) } -//发送短信 +// 发送短信 func (that *dingdongyun) send(mUrl string, umoblie string, content string) (bool, error) { data_send_sms_yzm := url.Values{"apikey": {that.ApiKey}, "mobile": {umoblie}, "content": {content}} @@ -74,7 +74,7 @@ func (that *dingdongyun) send(mUrl string, umoblie string, content string) (bool return true, nil } -//调用url发送短信的连接 +// 调用url发送短信的连接 func (that *dingdongyun) httpsPostForm(url string, data url.Values) (string, error) { resp, err := http.PostForm(url, data) diff --git a/dri/wechat/h5program.go b/dri/wechat/h5program.go index 270d61f..c1abfb2 100644 --- a/dri/wechat/h5program.go +++ b/dri/wechat/h5program.go @@ -9,8 +9,8 @@ import ( "github.com/silenceper/wechat/v2/officialaccount/oauth" ) -//基于此文档开发 -//https://github.com/silenceper/wechat/blob/v2/doc/api/officialaccount.md +// 基于此文档开发 +// https://github.com/silenceper/wechat/blob/v2/doc/api/officialaccount.md type h5Program struct { Memory *cache.Memory Config *h5config.Config diff --git a/dri/wechat/pay.go b/dri/wechat/pay.go index 4111579..52f8669 100644 --- a/dri/wechat/pay.go +++ b/dri/wechat/pay.go @@ -9,8 +9,8 @@ import ( "time" ) -//基于此文档开发 -//https://github.com/silenceper/wechat/blob/v2/doc/api/officialaccount.md +// 基于此文档开发 +// https://github.com/silenceper/wechat/blob/v2/doc/api/officialaccount.md type wxpay struct { client *wechat.ClientV3 ctx context.Context diff --git a/manage/manage.go b/manage/manage.go index a003655..e745f15 100644 --- a/manage/manage.go +++ b/manage/manage.go @@ -109,7 +109,7 @@ func copyDir(src string, dest string) { } } -//egodic directories +// egodic directories func getFilelist(path string) { err := filepath.Walk(path, func(path string, f os.FileInfo, err error) error { if f == nil { @@ -136,7 +136,7 @@ func PathExists(path string) (bool, error) { return false, err } -//copy file +// copy file func CopyFile(src, dst string) (w int64, err error) { srcFile, err := os.Open(src) if err != nil { diff --git a/session.go b/session.go index 1faf14d..d3385f8 100644 --- a/session.go +++ b/session.go @@ -3,14 +3,16 @@ package hotime import ( . "code.hoteas.com/golang/hotime/cache" . "code.hoteas.com/golang/hotime/common" + //"sync" ) -//session对象 +// session对象 type SessionIns struct { *HoTimeCache SessionId string Map ContextBase + //mutex sync.Mutex } func (that *SessionIns) set() { @@ -25,10 +27,14 @@ func (that *SessionIns) Session(key string, data ...interface{}) *Obj { if len(data) != 0 { if data[0] == nil { + //that.mutex.Lock() delete(that.Map, key) + //that.mutex.Unlock() that.set() } else { + //that.mutex.Lock() that.Map[key] = data[0] + //that.mutex.Unlock() that.set() } return &Obj{Data: nil} @@ -52,5 +58,6 @@ func (that *SessionIns) get() { } func (that *SessionIns) Init(cache *HoTimeCache) { + //that.mutex=sync.Mutex{} that.HoTimeCache = cache }