多排序字段用sql查询很方便,例如:
select * from user order by score desc,name desc
有两个字段 sort(score,name)。
在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
关于sorting - redis按多字段排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17975270/