feat(redis):add LpopCount,RpopCount (#2990)

This commit is contained in:
fabio
2023-03-09 13:45:45 +08:00
committed by GitHub
parent 03391b48ca
commit cb7f3e8a17
2 changed files with 76 additions and 0 deletions

View File

@@ -1170,6 +1170,26 @@ func (s *Redis) LpopCtx(ctx context.Context, key string) (val string, err error)
return
}
// LpopCount is the implementation of redis lpopCount command.
func (s *Redis) LpopCount(key string, count int) ([]string, error) {
return s.LpopCountCtx(context.Background(), key, count)
}
// LpopCountCtx is the implementation of redis lpopCount command.
func (s *Redis) LpopCountCtx(ctx context.Context, key string, count int) (val []string, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
return err
}
val, err = conn.LPopCount(ctx, key, count).Result()
return err
}, acceptable)
return
}
// Lpush is the implementation of redis lpush command.
func (s *Redis) Lpush(key string, values ...any) (int, error) {
return s.LpushCtx(context.Background(), key, values...)
@@ -1432,6 +1452,26 @@ func (s *Redis) RpopCtx(ctx context.Context, key string) (val string, err error)
return
}
// RpopCount is the implementation of redis rpopCount command.
func (s *Redis) RpopCount(key string, count int) ([]string, error) {
return s.RpopCountCtx(context.Background(), key, count)
}
// RpopCountCtx is the implementation of redis rpopCount command.
func (s *Redis) RpopCountCtx(ctx context.Context, key string, count int) (val []string, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
return err
}
val, err = conn.RPopCount(ctx, key, count).Result()
return err
}, acceptable)
return
}
// Rpush is the implementation of redis rpush command.
func (s *Redis) Rpush(key string, values ...any) (int, error) {
return s.RpushCtx(context.Background(), key, values...)