mirror of https://github.com/rocboss/paopao-ce
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
762 B
35 lines
762 B
2 years ago
|
// Copyright 2023 ROC. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package conf
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"sync"
|
||
|
|
||
|
"github.com/rueian/rueidis"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
_redisClient rueidis.Client
|
||
|
_once sync.Once
|
||
|
)
|
||
|
|
||
|
func MustRedisClient() rueidis.Client {
|
||
|
_once.Do(func() {
|
||
|
client, err := rueidis.NewClient(rueidis.ClientOption{
|
||
|
InitAddress: redisSetting.InitAddress,
|
||
|
Username: redisSetting.Username,
|
||
|
Password: redisSetting.Password,
|
||
|
SelectDB: redisSetting.SelectDB,
|
||
|
ConnWriteTimeout: redisSetting.ConnWriteTimeout,
|
||
|
})
|
||
|
if err != nil {
|
||
|
log.Fatalf("create a redis client failed: %s", err)
|
||
|
}
|
||
|
_redisClient = client
|
||
|
})
|
||
|
return _redisClient
|
||
|
}
|