add action,login log
CI / changes (push) Successful in 4s
CI / docker-bff (push) Failing after 2s
CI / docker-product (push) Failing after 2s
CI / docker-admin (push) Failing after 1s
CI / docker-user (push) Failing after 1s

This commit is contained in:
2026-08-20 17:35:04 +08:00
parent f360c268be
commit f49d155373
16 changed files with 637 additions and 27 deletions
+54
View File
@@ -0,0 +1,54 @@
package logRedis
import (
"context"
"fmt"
"time"
goredis "github.com/redis/go-redis/v9"
)
const Nil = goredis.Nil
var LogRedisClient *goredis.Client
type LogRedisConfig struct {
Host string
Port int
Password string
DB int
}
func Init(c LogRedisConfig) error {
client, err := New(c)
if err != nil {
return err
}
LogRedisClient = client
return nil
}
func New(c LogRedisConfig) (*goredis.Client, error) {
if c.Host == "" {
return nil, fmt.Errorf("redis: Host is empty")
}
if c.Port == 0 {
c.Port = 6379
}
client := goredis.NewClient(&goredis.Options{
Addr: fmt.Sprintf("%s:%d", c.Host, c.Port),
Password: c.Password,
DB: c.DB,
})
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
if err := client.Ping(ctx).Err(); err != nil {
_ = client.Close()
return nil, fmt.Errorf("redis ping: %w", err)
}
return client, nil
}