Support redis command Rpop (#431)

* ss

* ss

* add go-zero:stores:redis-command:Rpop and redis_test

* Delete 1.go

* support redis command Rpop

Co-authored-by: fanhongyi <fanhongyi@tal.com>
master
foyon 4 years ago committed by GitHub
parent 76026fc211
commit 8b273a075c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -751,6 +751,20 @@ func (s *Redis) Pipelined(fn func(Pipeliner) error) (err error) {
return return
} }
func (s *Redis) Rpop(key string) (val string, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
return err
}
val, err = conn.RPop(key).Result()
return err
}, acceptable)
return
}
func (s *Redis) Rpush(key string, values ...interface{}) (val int, err error) { func (s *Redis) Rpush(key string, values ...interface{}) (val int, err error) {
err = s.brk.DoWithAcceptable(func() error { err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s) conn, err := getRedis(s)

@ -272,7 +272,12 @@ func TestRedis_List(t *testing.T) {
val, err = client.Lpush("key", "value1", "value2") val, err = client.Lpush("key", "value1", "value2")
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, 5, val) assert.Equal(t, 5, val)
val, err = client.Rpush("key", "value3", "value3") _, err = NewRedis(client.Addr, "").Rpop("key")
assert.NotNil(t, err)
v, err = client.Rpop("key")
assert.Nil(t, err)
assert.Equal(t, "value4", v)
val, err = client.Rpush("key", "value4", "value3", "value3")
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, 7, val) assert.Equal(t, 7, val)
_, err = NewRedis(client.Addr, "").Lrem("key", 2, "value1") _, err = NewRedis(client.Addr, "").Lrem("key", 2, "value1")

Loading…
Cancel
Save