commit missing method for redis (#1325)

* commit `decr ` `decrby` `lindex` missing method for redis

* fix(store_test):TestRedis_DecrBy

* add unit tests for redis commands. And put the functions in alphabetical order

* put the functions in alphabetical order

* add `lindex` unit test

* sort func
This commit is contained in:
CrazyZard
2021-12-15 13:15:39 +08:00
committed by GitHub
parent a290ff4486
commit a7bd993c0c
4 changed files with 141 additions and 0 deletions

View File

@@ -238,6 +238,36 @@ func (s *Redis) BlpopEx(redisNode RedisNode, key string) (string, bool, error) {
return vals[1], true, nil
}
// Decr is the implementation of redis decr command.
func (s *Redis) Decr(key string) (val int64, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
return err
}
val, err = conn.Decr(key).Result()
return err
}, acceptable)
return
}
// Decrby is the implementation of redis decrby command.
func (s *Redis) Decrby(key string, increment int64) (val int64, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
return err
}
val, err = conn.DecrBy(key, increment).Result()
return err
}, acceptable)
return
}
// Del deletes keys.
func (s *Redis) Del(keys ...string) (val int, err error) {
err = s.brk.DoWithAcceptable(func() error {
@@ -765,6 +795,21 @@ func (s *Redis) Llen(key string) (val int, err error) {
return
}
// Lindex is the implementation of redis lindex command.
func (s *Redis) Lindex(key string, index int64) (val string, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
return err
}
val, err = conn.LIndex(key, index).Result()
return err
}, acceptable)
return
}
// Lpop is the implementation of redis lpop command.
func (s *Redis) Lpop(key string) (val string, err error) {
err = s.brk.DoWithAcceptable(func() error {