@@ -23,21 +23,21 @@ ZPOPMAX removes and returns the member with the highest score from the sorted se
2323
2424If the key does not exist, the command returns empty list. An optional "count" argument can be provided
2525to remove and return multiple members (up to the number specified).
26+
27+ When popped, the elements are returned in descending order of score and you get the rank of the element in the sorted set.
28+ The rank is 1-based, which means that the first element is at rank 1 and not rank 0.
29+ The 1), 2), 3), ... is the rank of the element in the sorted set.
2630 ` ,
2731 Examples : `
28- localhost:7379> ZADD users 1 alice
29- OK 1
30- localhost:7379> ZADD users 2 bob
31- OK 1
32- localhost:7379> ZADD users 3 charlie
33- OK 1
32+ localhost:7379> ZADD users 10 alice 20 bob 30 charlie
33+ OK 3
3434localhost:7379> ZPOPMAX users
3535OK
36- 0) 3 , charlie
36+ 3) 30 , charlie
3737localhost:7379> ZPOPMAX users 10
3838OK
39- 0) 2 , bob
40- 1) 1 , alice
39+ 2) 20 , bob
40+ 1) 10 , alice
4141 ` ,
4242 Eval : evalZPOPMAX ,
4343 Execute : executeZPOPMAX ,
@@ -97,6 +97,7 @@ func evalZPOPMAX(c *Cmd, s *dstore.Store) (*CmdRes, error) {
9797
9898 ss = obj .Value .(* types.SortedSet )
9999 elements := make ([]* wire.ZElement , 0 , count )
100+ totalElements := ss .SortedSet .GetCount ()
100101
101102 for i := 0 ; i < count ; i ++ {
102103 n := ss .PopMax ()
@@ -106,6 +107,7 @@ func evalZPOPMAX(c *Cmd, s *dstore.Store) (*CmdRes, error) {
106107 elements = append (elements , & wire.ZElement {
107108 Member : n .Key (),
108109 Score : int64 (n .Score ()),
110+ Rank : int64 (totalElements ) - int64 (i ),
109111 })
110112 }
111113 return newZPOPMAXRes (elements ), nil
0 commit comments