feat:完善redis封装

This commit is contained in:
Amnesia
2026-03-13 15:32:48 +08:00
parent 63c5ec7ac7
commit cf83e11778
2 changed files with 28 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package redis
import (
"context"
"errors"
"time"
redis "github.com/redis/go-redis/v9"
@@ -14,6 +15,27 @@ func (c *Client) ZincrBy(ctx context.Context, key string, member string, score f
return c.rdb.ZIncrBy(ctx, key, score, member).Err()
}
func (c *Client) ZAdd(ctx context.Context, key string, members ...redis.Z) error {
if c == nil || c.rdb == nil {
return nil
}
return c.rdb.ZAdd(ctx, key, members...).Err()
}
func (c *Client) ZRemRangeByRank(ctx context.Context, key string, start int64, stop int64) error {
if c == nil || c.rdb == nil {
return nil
}
return c.rdb.ZRemRangeByRank(ctx, key, start, stop).Err()
}
func (c *Client) ZRangeWithScores(ctx context.Context, key string, start int64, stop int64) ([]redis.Z, error) {
if c == nil || c.rdb == nil {
return nil, errors.New("redis client not initialized")
}
return c.rdb.ZRangeWithScores(ctx, key, start, stop).Result()
}
func (c *Client) Expire(ctx context.Context, key string, ttl time.Duration) error {
if c == nil || c.rdb == nil {
return nil