您可以通过一个HASH字段对SET进行排序来实现它.因此,您应该创建所有哈希值的索引SET,并使用该BY
选项.此外,您可以使用DESC
选项将结果从高到低排序.
例如
localhost:6379> sadd indices h1 h2 h3 h4
(integer) 4
localhost:6379> hset h1 score 3
(integer) 1
localhost:6379> hset h2 score 2
(integer) 1
localhost:6379> hset h3 score 5
(integer) 1
localhost:6379> hset h4 score 1
(integer) 1
localhost:6379> sort indices by *->score
1) "h4"
2) "h2"
3) "h1"
4) "h3"
localhost:6379> sort indices by *->score desc
1) "h3"
2) "h1"
3) "h2"
4) "h4"
Run Code Online (Sandbox Code Playgroud)