Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redis sorted set highest score

Tags:

ruby

redis

Is any simple method to get the highest score from Redis sorted set? I found this way, may be there is better ways to make this(in ruby):

all_scores = Redis.zrange('foo', 0, -1, with_scores: true) # => [["item 1", 2.5], ["item 2", 3.4]]
all_scores.flatten.last # => 3.4

It seems not the best way.

like image 936
Vladimir Titov Avatar asked Dec 05 '22 17:12

Vladimir Titov


1 Answers

you can use ZREVRANGE command.

ZREVRANGE foo 0 0 withscores

This will give you the highest score and it's value.

http://redis.io/commands/zrevrange

like image 85
Karthikeyan Gopall Avatar answered Jan 07 '23 16:01

Karthikeyan Gopall