Skip to content

Commit 0685c70

Browse files
committed
redis support without password
1 parent 3202e68 commit 0685c70

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

utils/cryptoutil/CryptoUtil_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ func TestMD5Encrypt(t *testing.T) {
1717
}
1818

1919
func TestHmacMD5Encrypt(t *testing.T) {
20-
t.Log(HmacMD5("1234",[]byte("123456")))
20+
t.Log(HmacMD5("test0",[]byte("zxcv1234")))
2121
}

utils/redisutil/RedisUtil.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ var redisClients map[string]*redis.Client = make(map[string]*redis.Client)
1414
func InitFromConfig(configs []interface{}, decryptKey string, decryptHandler func(content string, decryptKey string) string) bool {
1515
for _, config := range configs {
1616
configMap := config.(map[string]interface{})
17-
if configMap["RedisName"] == nil || configMap["Addr"] == nil || configMap["Password"] == nil || configMap["DB"] == nil {
18-
logutil.Error("RedisName、Addr、Password、DB为必填项", nil)
17+
if configMap["RedisName"] == nil || configMap["Addr"] == nil {
18+
logutil.Error("RedisName、Addr为必填项", nil)
1919
return false
2020
}
2121
redisName := configMap["RedisName"].(string)
2222
addr := configMap["Addr"].(string)
23-
password := decryptHandler(configMap["Password"].(string), decryptKey)
24-
db := int(configMap["DB"].(float64))
23+
password := ""
24+
if configMap["Password"] != nil {
25+
password = decryptHandler(configMap["Password"].(string), decryptKey)
26+
}
27+
db := 0
28+
if configMap["DB"] != nil {
29+
db = int(configMap["DB"].(float64))
30+
}
2531
maxRetries := -1
2632
poolSize := 200
2733
minIdleConns := 100

0 commit comments

Comments
 (0)