调度中心嵌入cms

This commit is contained in:
vet
2026-05-28 13:29:24 +08:00
parent 52446ccf3f
commit 5f93d025d2
17 changed files with 262 additions and 20 deletions

View File

@@ -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
View 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
}