This commit is contained in:
oneao committed 2026-02-26 17:31:08 +08:00
1 parent 4ce951dd56
commit 8a3dea8545
44 files changed
+1599 -30

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
package config
import (
"context"
"fmt"
"time"
"github.com/redis/go-redis/v9"
)
func initRedis() (*redis.Client, error) {
cfg := GetConf().Redis
rdb := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port),
Password: cfg.Password,
DB: cfg.Db,
})
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
if err := rdb.Ping(ctx).Err(); err != nil {
_ = rdb.Close()
return nil, fmt.Errorf("redis ping failed: %w", err)
}
return rdb, nil
}