Skip to content

Commit

Permalink
Merge pull request #76 from sunmi-OS/patch1
Browse files Browse the repository at this point in the history
update redis sdk
  • Loading branch information
luduoxin authored Aug 25, 2022
2 parents b3cf0e5 + f472ee4 commit 955e16a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 0 additions & 3 deletions api/ecode/ecode.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package ecode

import (
"fmt"

"github.com/spf13/cast"
)

var errorMap = map[string]int{}

// New 注册Error异常
func New(code int, err error) error {
fmt.Println(err)
errorMap[err.Error()] = code
return err
}
Expand Down
11 changes: 8 additions & 3 deletions db/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redis

import (
"context"
"crypto/tls"
"strings"
"sync"

Expand Down Expand Up @@ -39,6 +40,7 @@ func newRedis(db string) (rc *redis.Client, err error) {
auth := viper.GetEnvConfig(redisName + ".auth").String()
encryption := viper.GetEnvConfig(redisName + ".encryption").Int64()
dbIndex := viper.GetEnvConfig(redisName + ".redisDB." + dbName).Int()
insecureSkipVerify := viper.GetEnvConfig(redisName + ".insecureSkipVerify").Bool()
if redisName == "redisServer" {
dbIndex = viper.GetEnvConfig("redisDB." + dbName).Int()
}
Expand All @@ -49,12 +51,15 @@ func newRedis(db string) (rc *redis.Client, err error) {
if !strings.Contains(addr, ":") {
addr = host + ":" + port
}

rc = redis.NewClient(&redis.Options{
ops := &redis.Options{
Addr: addr,
Password: auth,
DB: dbIndex,
})
}
if insecureSkipVerify {
ops.TLSConfig = &tls.Config{InsecureSkipVerify: true}
}
rc = redis.NewClient(ops)
if err := rc.Ping(context.Background()).Err(); err != nil {
return nil, err
}
Expand Down

0 comments on commit 955e16a

Please sign in to comment.