调度中心嵌入cms
This commit is contained in:
@@ -20,6 +20,7 @@ type Config struct {
|
||||
BusinessMongoDatabase string
|
||||
SchedulerMongoDatabase string
|
||||
RedisAddr string
|
||||
RedisUsername string
|
||||
RedisPassword string
|
||||
}
|
||||
|
||||
@@ -37,6 +38,7 @@ func Load() Config {
|
||||
BusinessMongoDatabase: getenv("MONGO_DATABASE", "openim_v3"),
|
||||
SchedulerMongoDatabase: getenv("SCHEDULER_MONGO_DATABASE", "scheduler_center"),
|
||||
RedisAddr: getenv("REDIS_ADDR", ""),
|
||||
RedisUsername: getenv("REDIS_USERNAME", ""),
|
||||
RedisPassword: getenv("REDIS_PASSWORD", ""),
|
||||
}
|
||||
}
|
||||
|
||||
22
pkg/redis/client.go
Normal file
22
pkg/redis/client.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
goredis "github.com/redis/go-redis/v9"
|
||||
|
||||
"scheduler-backend/pkg/config"
|
||||
)
|
||||
|
||||
func Connect(ctx context.Context, cfg config.Config) (*goredis.Client, error) {
|
||||
client := goredis.NewClient(&goredis.Options{
|
||||
Addr: cfg.RedisAddr,
|
||||
Username: cfg.RedisUsername,
|
||||
Password: cfg.RedisPassword,
|
||||
})
|
||||
if err := client.Ping(ctx).Err(); err != nil {
|
||||
_ = client.Close()
|
||||
return nil, err
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
Reference in New Issue
Block a user