Skip to content

Commit

Permalink
feat: 支持redis的LTrim方法 (zeromicro#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
shenbaise9527 authored Jan 16, 2022
1 parent 468c237 commit 13db7a1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/stores/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,18 @@ func (s *Redis) Lrem(key string, count int, value string) (val int, err error) {
return
}

// Ltrim is the implementation of redis ltrim command.
func (s *Redis) Ltrim(key string, start, stop int64) error {
return s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
return err
}

return conn.LTrim(key, start, stop).Err()
}, acceptable)
}

// Mget is the implementation of redis mget command.
func (s *Redis) Mget(keys ...string) (val []string, err error) {
err = s.brk.DoWithAcceptable(func() error {
Expand Down
5 changes: 5 additions & 0 deletions core/stores/redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ func TestRedis_List(t *testing.T) {
vals, err = client.Lrange("key", 0, 10)
assert.Nil(t, err)
assert.EqualValues(t, []string{"value2", "value3", "value4"}, vals)
err = client.Ltrim("key", 0, 1)
assert.Nil(t, err)
vals, err = client.Lrange("key", 0, 10)
assert.Nil(t, err)
assert.EqualValues(t, []string{"value2", "value3"}, vals)
})
}

Expand Down

0 comments on commit 13db7a1

Please sign in to comment.