feat: add getset command in redis and kv (#1693)

This commit is contained in:
benqi
2022-03-23 18:02:56 +08:00
committed by GitHub
parent c1d9e6a00b
commit bbac994c8a
4 changed files with 80 additions and 0 deletions

View File

@@ -615,6 +615,31 @@ func (s *Redis) GetCtx(ctx context.Context, key string) (val string, err error)
return
}
// GetSet is the implementation of redis getset command.
func (s *Redis) GetSet(key, value string) (string, error) {
return s.GetSetCtx(context.Background(), key, value)
}
// GetSetCtx is the implementation of redis getset command.
func (s *Redis) GetSetCtx(ctx context.Context, key, value string) (val string, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
return err
}
if val, err = conn.GetSet(ctx, key, value).Result(); err == red.Nil {
return nil
} else if err != nil {
return err
} else {
return nil
}
}, acceptable)
return
}
// GetBit is the implementation of redis getbit command.
func (s *Redis) GetBit(key string, offset int64) (int, error) {
return s.GetBitCtx(context.Background(), key, offset)