redis - REIDS 排名问题, 取前后5名
怪我咯
怪我咯 2017-04-22 08:59:51
0
1
724

用 zAdd 加入排名

zAdd ranks 1000 老王
zAdd ranks 1001 如花
zAdd ranks 1002 死鱼
....

想取 用户老王及老王的前后各5名, 有没有简便方法?

谢谢。

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
黄舟

First, get Lao Wang’s current ranking: ZRANK ranks 老王, assuming Lao Wang’s ranking is Nth.

(The top 5 I am talking about here refer to those with a higher score than Lao Wang, and the bottom 5 are those with a smaller score than Lao Wang)
Then Lao Wang’s top 5 are: ZRANGE ranks N+1 N+6,
Lao Wang’s last 5 are: ZRANGE ranks N-6 N-1.

To put it all together, plus Lao Wang himself, it is: ZRANGE ranks N-6 N+6.

Note: You must remember to first determine whether N-6 and N-1 are less than 0.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!