Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用sql查询多排序字段很容易。例如:
select * from user order by score desc,name desc
有两个字段排序(分数,名称)。
应该如何在redis中做到这一点?
使用按分数排序的 redis 排序集。您必须根据自己的需要准备分数。
finalScore = score*MAX_NAME_VALUE + getIntRepresentation(name) //MAX_NAME_VALUE is the maximum value returned by getIntRepresentation() method
然后使用
zadd myset finalScore value
和公正的使用
zrevrange myset 0 10