add redis Zrevrank (#137)

* update goctl rpc template log print url

* add redis Zrevrank

Co-authored-by: zhangkai <zhangkai@laoyuegou.com>
master
mywaystay 4 years ago committed by GitHub
parent 81bf122fa4
commit 33faab61a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -73,6 +73,7 @@ type (
ZrevrangebyscoreWithScores(key string, start, stop int64) ([]redis.Pair, error) ZrevrangebyscoreWithScores(key string, start, stop int64) ([]redis.Pair, error)
ZrevrangebyscoreWithScoresAndLimit(key string, start, stop int64, page, size int) ([]redis.Pair, error) ZrevrangebyscoreWithScoresAndLimit(key string, start, stop int64, page, size int) ([]redis.Pair, error)
Zscore(key string, value string) (int64, error) Zscore(key string, value string) (int64, error)
Zrevrank(key, field string) (int64, error)
} }
clusterStore struct { clusterStore struct {
@ -644,6 +645,15 @@ func (cs clusterStore) Zscore(key string, value string) (int64, error) {
return node.Zscore(key, value) return node.Zscore(key, value)
} }
func (cs clusterStore) Zrevrank(key, field string) (int64, error) {
node, err := cs.getRedis(key)
if err != nil {
return 0, err
}
return node.Zrevrank(key, field)
}
func (cs clusterStore) getRedis(key string) (*redis.Redis, error) { func (cs clusterStore) getRedis(key string) (*redis.Redis, error) {
if val, ok := cs.dispatcher.Get(key); !ok { if val, ok := cs.dispatcher.Get(key); !ok {
return nil, ErrNoRedisNode return nil, ErrNoRedisNode

@ -1273,6 +1273,20 @@ func (s *Redis) ZrevrangebyscoreWithScoresAndLimit(key string, start, stop int64
return return
} }
func (s *Redis) Zrevrank(key string, field string) (val int64, err error) {
err = s.brk.DoWithAcceptable(func() error {
conn, err := getRedis(s)
if err != nil {
return err
}
val, err = conn.ZRevRank(key, field).Result()
return err
}, acceptable)
return
}
func (s *Redis) String() string { func (s *Redis) String() string {
return s.Addr return s.Addr
} }

@ -584,6 +584,9 @@ func TestRedis_SortedSet(t *testing.T) {
rank, err := client.Zrank("key", "value2") rank, err := client.Zrank("key", "value2")
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, int64(1), rank) assert.Equal(t, int64(1), rank)
rank, err = client.Zrevrank("key", "value1")
assert.Nil(t, err)
assert.Equal(t, int64(2), rank)
_, err = NewRedis(client.Addr, "").Zrank("key", "value4") _, err = NewRedis(client.Addr, "").Zrank("key", "value4")
assert.NotNil(t, err) assert.NotNil(t, err)
_, err = client.Zrank("key", "value4") _, err = client.Zrank("key", "value4")

Loading…
Cancel
Save