建立仓库

This commit is contained in:
2025-08-05 10:51:35 +08:00
commit 4bbc05fe1f
36 changed files with 1946 additions and 0 deletions

31
clients/redis.go Normal file
View File

@@ -0,0 +1,31 @@
package clients
import (
redis "github.com/redis/go-redis/v9"
"log/slog"
"os"
)
var Redis *redis.Client
func InitRedis() {
host := os.Getenv("REDIS_HOST")
if host == "" {
slog.Debug("REDIS_HOST 环境变量未设置,使用默认值 localhost")
host = "localhost"
}
port := os.Getenv("REDIS_PORT")
if port == "" {
slog.Debug("REDIS_PORT 环境变量未设置,使用默认值 6379")
port = "6379"
}
password := os.Getenv("REDIS_PASSWORD")
if password == "" {
slog.Debug("REDIS_PASSWORD 环境变量未设置,使用默认值空字符串")
}
Redis = redis.NewClient(&redis.Options{
Addr: host + ":" + port,
Password: password,
})
}