1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<?php
$server = "localhost";
$port = 6379; $timeout = 2.5;
$redis = new Redis();
$redis->connect($server,$port,$timeout);
// 得点
$userPoint = array(
'さんま' => 200000,
'たけし' => 4000,
'ところ' => 300,
'いたお' => 200,
'はまだ' => 100,
'やまだ' => 100,
'はざま' => 40
);
// 得点をセットする
foreach( $userPoint as $user => $point ) {
$redis->zAdd('test_rank', $point, $user );
}
// 一覧を表示する
$ranking = $redis->zRevRange( 'test_rank', 0, -1, true );
foreach($ranking as $user => $score ) {
$score++;
echo "$user=".($redis->zCount('test_rank', $score, '+inf')+1)."\n";
}
|