Compare commits

..

No commits in common. "f5ba9b2f97fea5a8e0fa83482666640f2eca7424" and "71983652a939f8369da1a1ba7adfd6a041fc9b72" have entirely different histories.

3 changed files with 52 additions and 44 deletions

View File

@ -1,21 +1,5 @@
# CHANGELOG - redis # CHANGELOG - redis
## v1.5.5 (2026-06-20)
- **JS 导出重构**:
- 移除 `js_export.go` 中冗余的独立命令快捷函数SET, GET, DEL, EXISTS, EXPIRE, PUBLISH统一通过 `Do` 方法调用。
- 移除未使用的 PascalCase 实例方法SET, GET, DEL, EXISTS, EXPIRE, HSET, HGET, PUBLISH精简 API 面积。
- 新增 `getDefaultRedisForJS` 单例模式,从 Context 中提取 `log.Logger` 传入 `GetRedis`,确保 JS 端 Redis 操作具备完整日志追踪能力。
- 新增 `MakeID` 函数,为 JS 端暴露分布式 ID 生成能力。
## v1.5.4 (2026-06-19)
- **基础设施对齐**: 内部依赖统一升级至 v1.5.x 语义版本。
## v1.5.3 (2026-06-18)
- **JS 导出增强**: 对齐 PascalCase 命名规范,扁平化 default 实例的 JS 导出。
## v1.5.2 (2026-06-17)
- **依赖修复**: 对齐 `encoding` v1.5.2 接口变更。
## v1.5.1 (2026-06-08) ## v1.5.1 (2026-06-08)
- **新增**: `SetConfig(name, setting string)` 方法,支持动态配置 Redis 连接(不依赖配置文件),方便通过别名获取连接。 - **新增**: `SetConfig(name, setting string)` 方法,支持动态配置 Redis 连接(不依赖配置文件),方便通过别名获取连接。
- **优化**: 重构配置加载逻辑,确保动态配置与配置文件配置的共存与优先级。 - **优化**: 重构配置加载逻辑,确保动态配置与配置文件配置的共存与优先级。

22
go.mod
View File

@ -3,21 +3,21 @@ module apigo.cc/go/redis
go 1.25.0 go 1.25.0
require ( require (
apigo.cc/go/cast v1.5.2 apigo.cc/go/cast v1.5.0
apigo.cc/go/config v1.5.2 apigo.cc/go/config v1.5.0
apigo.cc/go/crypto v1.5.2 apigo.cc/go/crypto v1.5.0
apigo.cc/go/encoding v1.5.3 apigo.cc/go/encoding v1.5.0
apigo.cc/go/id v1.5.3 apigo.cc/go/id v1.5.0
apigo.cc/go/jsmod v1.5.2 apigo.cc/go/jsmod v1.5.0
apigo.cc/go/log v1.5.6 apigo.cc/go/log v1.5.0
apigo.cc/go/safe v1.5.1 apigo.cc/go/safe v1.5.0
github.com/gomodule/redigo v2.0.0+incompatible github.com/gomodule/redigo v2.0.0+incompatible
) )
require ( require (
apigo.cc/go/file v1.5.4 // indirect apigo.cc/go/file v1.5.0 // indirect
apigo.cc/go/rand v1.5.2 // indirect apigo.cc/go/rand v1.5.0 // indirect
apigo.cc/go/shell v1.5.2 // indirect apigo.cc/go/shell v1.5.0 // indirect
golang.org/x/crypto v0.52.0 // indirect golang.org/x/crypto v0.52.0 // indirect
golang.org/x/sys v0.45.0 // indirect golang.org/x/sys v0.45.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect

View File

@ -7,7 +7,6 @@ import (
"apigo.cc/go/id" "apigo.cc/go/id"
"apigo.cc/go/jsmod" "apigo.cc/go/jsmod"
"apigo.cc/go/log"
) )
func init() { func init() {
@ -27,7 +26,7 @@ func init() {
// 默认快捷调用 (面向 "default" 实例) // 默认快捷调用 (面向 "default" 实例)
"Do": func(ctx context.Context, cmd string, args ...any) (*Result, error) { "Do": func(ctx context.Context, cmd string, args ...any) (*Result, error) {
jr := getDefaultRedisForJS(ctx) jr := &jsRedis{rd: GetRedis("default", nil), ctx: ctx}
if jr.rd.Error != nil { if jr.rd.Error != nil {
return nil, jr.rd.Error return nil, jr.rd.Error
} }
@ -35,12 +34,36 @@ func init() {
return res, res.Error return res, res.Error
}, },
"MakeID": func(ctx context.Context, size int, forDB *string) string { // 常用命令平铺 (面向 "default" 实例)
jr := getDefaultRedisForJS(ctx) "SET": func(ctx context.Context, key string, val any) (*Result, error) {
if jr.rd.Error != nil { jr := &jsRedis{rd: GetRedis("default", nil), ctx: ctx}
return id.MakeID(size) res := jr.Do("SET", key, val)
} return res, res.Error
return jr.MakeID(size, forDB) },
"GET": func(ctx context.Context, key string) (*Result, error) {
jr := &jsRedis{rd: GetRedis("default", nil), ctx: ctx}
res := jr.Do("GET", key)
return res, res.Error
},
"DEL": func(ctx context.Context, key string) (*Result, error) {
jr := &jsRedis{rd: GetRedis("default", nil), ctx: ctx}
res := jr.Do("DEL", key)
return res, res.Error
},
"EXISTS": func(ctx context.Context, key string) (*Result, error) {
jr := &jsRedis{rd: GetRedis("default", nil), ctx: ctx}
res := jr.Do("EXISTS", key)
return res, res.Error
},
"EXPIRE": func(ctx context.Context, key string, seconds int) (*Result, error) {
jr := &jsRedis{rd: GetRedis("default", nil), ctx: ctx}
res := jr.Do("EXPIRE", key, seconds)
return res, res.Error
},
"PUBLISH": func(ctx context.Context, channel, data string) (*Result, error) {
jr := &jsRedis{rd: GetRedis("default", nil), ctx: ctx}
res := jr.Do("PUBLISH", channel, data)
return res, res.Error
}, },
}) })
} }
@ -51,15 +74,6 @@ type jsRedis struct {
idMaker *id.IDMaker idMaker *id.IDMaker
} }
var defaultRedisForJS *jsRedis
func getDefaultRedisForJS(ctx context.Context) *jsRedis {
if defaultRedisForJS == nil {
defaultRedisForJS = &jsRedis{rd: GetRedis("default", ctx.Value("Logger").(*log.Logger)), ctx: ctx}
}
return defaultRedisForJS
}
var errSafeMode = errors.New("redis operation is restricted in safe mode") var errSafeMode = errors.New("redis operation is restricted in safe mode")
// 核心写操作指令集 // 核心写操作指令集
@ -91,6 +105,16 @@ func (jr *jsRedis) Do(cmd string, args ...any) *Result {
return jr.rd.Do(cmd, args...) return jr.rd.Do(cmd, args...)
} }
// 实例方法 PascalCase 对齐
func (jr *jsRedis) SET(key string, val any) *Result { return jr.Do("SET", key, val) }
func (jr *jsRedis) GET(key string) *Result { return jr.Do("GET", key) }
func (jr *jsRedis) DEL(key string) *Result { return jr.Do("DEL", key) }
func (jr *jsRedis) EXISTS(key string) *Result { return jr.Do("EXISTS", key) }
func (jr *jsRedis) EXPIRE(key string, s int) *Result { return jr.Do("EXPIRE", key, s) }
func (jr *jsRedis) HSET(key, field string, v any) *Result { return jr.Do("HSET", key, field, v) }
func (jr *jsRedis) HGET(key, field string) *Result { return jr.Do("HGET", key, field) }
func (jr *jsRedis) PUBLISH(ch, data string) *Result { return jr.Do("PUBLISH", ch, data) }
// ID Generation // ID Generation
func (jr *jsRedis) MakeID(size int, forDB *string) string { func (jr *jsRedis) MakeID(size int, forDB *string) string {
if jr.idMaker == nil { if jr.idMaker == nil {