Skip to content

Commit

Permalink
fix: chat config path
Browse files Browse the repository at this point in the history
Signed-off-by: Xinwei Xiong(cubxxw-openim) <[email protected]>
  • Loading branch information
cubxxw committed Jul 29, 2023
1 parent 1c71f7c commit 0cddaa1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
7 changes: 1 addition & 6 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,4 @@ adminList:
imAdmin: openIMAdmin


openIMUrl: "http://127.0.0.1:10002"

redis:
address: [ 127.0.0.1:16379 ]
username:
password: openIM123
openIMUrl: "http://127.0.0.1:10002"
6 changes: 3 additions & 3 deletions pkg/common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ var Config struct {
ListenIP string `yaml:"listenIP"`
} `yaml:"rpc"`
Redis struct {
Address []string `yaml:"address"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Address *[]string `yaml:"address"`
Username *string `yaml:"username"`
Password *string `yaml:"password"`
} `yaml:"redis"`
RpcPort struct {
OpenImAdminPort []int `yaml:"openImAdminPort"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/common/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ func InitConfig(configFile string) error {
configFieldCopy(&Config.Secret, imConfig.Secret)
configFieldCopy(&Config.TokenPolicy.Expire, imConfig.TokenPolicy.Expire)

// Redis
configFieldCopy(&Config.Redis.Address, imConfig.Redis.Address)
configFieldCopy(&Config.Redis.Password, imConfig.Redis.Password)
configFieldCopy(&Config.Redis.Username, imConfig.Redis.Username)

configData, err := yaml.Marshal(&Config)
fmt.Printf("debug: %s\nconfig:\n%s\n", time.Now(), string(configData))
if err != nil {
Expand Down
23 changes: 12 additions & 11 deletions pkg/common/db/cache/init_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"errors"
"fmt"
"github.com/OpenIMSDK/chat/pkg/common/config"
"time"

"github.com/OpenIMSDK/chat/pkg/common/config"

"github.com/redis/go-redis/v9"

"github.com/OpenIMSDK/tools/errs"
Expand All @@ -19,26 +20,26 @@ const (

// NewRedis Initialize redis connection.
func NewRedis() (redis.UniversalClient, error) {
if len(config.Config.Redis.Address) == 0 {
if len(*config.Config.Redis.Address) == 0 {
return nil, errors.New("redis address is empty")
}
specialerror.AddReplace(redis.Nil, errs.ErrRecordNotFound)
var rdb redis.UniversalClient
if len(config.Config.Redis.Address) > 1 {
if len(*config.Config.Redis.Address) > 1 {
rdb = redis.NewClusterClient(&redis.ClusterOptions{
Addrs: config.Config.Redis.Address,
Username: config.Config.Redis.Username,
Password: config.Config.Redis.Password, // no password set
Addrs: *config.Config.Redis.Address,
Username: *config.Config.Redis.Username,
Password: *config.Config.Redis.Password, // no password set
PoolSize: 50,
MaxRetries: maxRetry,
})
} else {
rdb = redis.NewClient(&redis.Options{
Addr: config.Config.Redis.Address[0],
Username: config.Config.Redis.Username,
Password: config.Config.Redis.Password, // no password set
DB: 0, // use default DB
PoolSize: 100, // connection pool size
Addr: (*config.Config.Redis.Address)[0],
Username: *config.Config.Redis.Username,
Password: *config.Config.Redis.Password, // no password set
DB: 0, // use default DB
PoolSize: 100, // connection pool size
MaxRetries: maxRetry,
})
}
Expand Down

0 comments on commit 0cddaa1

Please sign in to comment.