This commit is contained in:
kzkzzzz
2024-06-01 18:17:41 +08:00
parent e9756f7f54
commit 0b36406c6f
4 changed files with 12 additions and 12 deletions

View File

@@ -17,8 +17,8 @@ var (
DB: 0,
PoolSize: 16,
MinIdleConn: 4,
MaxConnAge: "1h",
IdleTimeout: "10m",
MaxConnAge: "4h",
IdleTimeout: "15m",
}
instanceMap = make(map[string]*MyRedis)
@@ -40,7 +40,7 @@ type (
}
)
func Instance(key ...string) *MyRedis {
func DB(key ...string) *MyRedis {
var key0 string
if len(key) > 0 {
@@ -170,7 +170,7 @@ func (r *MyRedis) SetJson(key string, value interface{}, t ...time.Duration) (st
}
func CloseInstance(key string) {
Instance(key).Client.Close()
DB(key).Client.Close()
}
func CloseAllInstance() {

View File

@@ -23,14 +23,14 @@ func TestRedis(t *testing.T) {
}
defer CloseAllInstance()
set, err := Instance().Set(context.Background(), "name", "qwe123", time.Minute).Result()
set, err := DB().Set(context.Background(), "name", "qwe123", time.Minute).Result()
if err != nil {
fmt.Println(err)
return
}
fmt.Println(set)
get, err := Instance().Get(context.Background(), "name").Result()
get, err := DB().Get(context.Background(), "name").Result()
if err != nil {
fmt.Println(err)
return