feat 初始化

This commit is contained in:
2026-10-29 10:12:22 +08:00
parent 332d812347
commit 09c1df8a22
81 changed files with 2211 additions and 7821 deletions

View File

@@ -48,3 +48,11 @@ func (c *CacheClient) Get(ctx context.Context, key string, dst interface{}) bool
}
return true
}
func (c *CacheClient) Exists(ctx context.Context, key ...string) bool {
n, err := c.cli.Exists(ctx, key...).Result()
if err != nil {
return false
}
return n > 0
}

View File

@@ -5,13 +5,12 @@ import (
"git.hlsq.asia/alex/service-common/config"
"git.hlsq.asia/alex/service-common/log"
"github.com/redis/go-redis/v9"
"time"
)
var instance *Client
type Client struct {
cli *redis.Client
*redis.Client
}
func Init(cfg *config.RedisConfig) error {
@@ -21,7 +20,7 @@ func Init(cfg *config.RedisConfig) error {
DB: cfg.DB,
})
instance = &Client{
cli: client,
Client: client,
}
cacheInstance = &CacheClient{
cli: client,
@@ -35,8 +34,8 @@ func Init(cfg *config.RedisConfig) error {
}
func Close() error {
if instance != nil && instance.cli != nil {
return instance.cli.Close()
if instance != nil && instance.Client != nil {
return instance.Client.Close()
}
return nil
}
@@ -44,43 +43,3 @@ func Close() error {
func GetClient() *Client {
return instance
}
func (c *Client) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd {
return c.cli.Set(ctx, key, value, expiration)
}
func (c *Client) SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd {
return c.cli.SetNX(ctx, key, value, expiration)
}
func (c *Client) Get(ctx context.Context, key string) *redis.StringCmd {
return c.cli.Get(ctx, key)
}
func (c *Client) HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd {
return c.cli.HSet(ctx, key, values...)
}
func (c *Client) HGet(ctx context.Context, key, field string) *redis.StringCmd {
return c.cli.HGet(ctx, key, field)
}
func (c *Client) HGetAll(ctx context.Context, key string) *redis.MapStringStringCmd {
return c.cli.HGetAll(ctx, key)
}
func (c *Client) HDel(ctx context.Context, key string, fields ...string) *redis.IntCmd {
return c.cli.HDel(ctx, key, fields...)
}
func (c *Client) Pipeline() redis.Pipeliner {
return c.cli.Pipeline()
}
func (c *Client) ScriptLoad(ctx context.Context, script string) *redis.StringCmd {
return c.cli.ScriptLoad(ctx, script)
}
func (c *Client) EvalSha(ctx context.Context, sha1 string, keys []string, args ...interface{}) *redis.Cmd {
return c.cli.EvalSha(ctx, sha1, keys, args...)
}