Fix basepool & 优化 repo
This commit is contained in:
@@ -75,10 +75,24 @@ func (s *RedisStore) Close() error {
|
||||
return s.client.Close()
|
||||
}
|
||||
|
||||
func (s *RedisStore) Expire(ctx context.Context, key string, expiration time.Duration) error {
|
||||
return s.client.Expire(ctx, key, expiration).Err()
|
||||
}
|
||||
|
||||
func (s *RedisStore) HSet(ctx context.Context, key string, values map[string]any) error {
|
||||
return s.client.HSet(ctx, key, values).Err()
|
||||
}
|
||||
|
||||
func (s *RedisStore) HGet(ctx context.Context, key, field string) (string, error) {
|
||||
val, err := s.client.HGet(ctx, key, field).Result()
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return "", ErrNotFound
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
func (s *RedisStore) HGetAll(ctx context.Context, key string) (map[string]string, error) {
|
||||
return s.client.HGetAll(ctx, key).Result()
|
||||
}
|
||||
@@ -111,6 +125,18 @@ func (s *RedisStore) Rotate(ctx context.Context, key string) (string, error) {
|
||||
return val, nil
|
||||
}
|
||||
|
||||
func (s *RedisStore) MSet(ctx context.Context, values map[string]any) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
// Redis MSet 命令需要 [key1, value1, key2, value2, ...] 格式的切片
|
||||
pairs := make([]interface{}, 0, len(values)*2)
|
||||
for k, v := range values {
|
||||
pairs = append(pairs, k, v)
|
||||
}
|
||||
return s.client.MSet(ctx, pairs...).Err()
|
||||
}
|
||||
|
||||
func (s *RedisStore) SAdd(ctx context.Context, key string, members ...any) error {
|
||||
return s.client.SAdd(ctx, key, members...).Err()
|
||||
}
|
||||
@@ -141,6 +167,13 @@ func (s *RedisStore) SRandMember(ctx context.Context, key string) (string, error
|
||||
return member, nil
|
||||
}
|
||||
|
||||
func (s *RedisStore) SUnionStore(ctx context.Context, destination string, keys ...string) (int64, error) {
|
||||
if len(keys) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
return s.client.SUnionStore(ctx, destination, keys...).Result()
|
||||
}
|
||||
|
||||
func (s *RedisStore) ZAdd(ctx context.Context, key string, members map[string]float64) error {
|
||||
if len(members) == 0 {
|
||||
return nil
|
||||
@@ -216,6 +249,17 @@ func (p *redisPipeliner) LPush(key string, values ...any) { p.pipe.LPush(p.ctx,
|
||||
func (p *redisPipeliner) LRem(key string, count int64, value any) {
|
||||
p.pipe.LRem(p.ctx, key, count, value)
|
||||
}
|
||||
|
||||
func (p *redisPipeliner) Set(key string, value []byte, expiration time.Duration) {
|
||||
p.pipe.Set(p.ctx, key, value, expiration)
|
||||
}
|
||||
|
||||
func (p *redisPipeliner) MSet(values map[string]any) {
|
||||
if len(values) == 0 {
|
||||
return
|
||||
}
|
||||
p.pipe.MSet(p.ctx, values)
|
||||
}
|
||||
func (p *redisPipeliner) SAdd(key string, members ...any) { p.pipe.SAdd(p.ctx, key, members...) }
|
||||
func (p *redisPipeliner) SRem(key string, members ...any) { p.pipe.SRem(p.ctx, key, members...) }
|
||||
func (p *redisPipeliner) ZAdd(key string, members map[string]float64) {
|
||||
|
||||
Reference in New Issue
Block a user