feat:完善redis封装
This commit is contained in:
@@ -3,6 +3,8 @@ package redis
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func (c *Client) GetBytes(ctx context.Context, key string) ([]byte, error) {
|
||||
@@ -16,3 +18,7 @@ func (c *Client) SetBytes(ctx context.Context, key string, value []byte, ttl tim
|
||||
func (c *Client) Del(ctx context.Context, key string) error {
|
||||
return c.rdb.Del(ctx, key).Err()
|
||||
}
|
||||
|
||||
func (c *Client) MGet(cacheCtx context.Context, cacheKeys ...string) *redis.SliceCmd {
|
||||
return c.rdb.MGet(cacheCtx, cacheKeys...)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user