PHP code example of jue / rank

1. Go to this page and download the library: Download jue/rank library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jue / rank example snippets


$rank = new CounterRank($redis,'activity','test');//新建一个counterRank

var_dump($rank->getRankKey());

//结果:	activity:test

$rank->addRankField(1, 2);

var_dump($rank->getRankScore(1));
//结果:	2	

$rank = new DateRank($redis,'activity','test', Carbon::now());

var_dump("rankKey:".$rank->getRankKey());

//结果:	
activity:test:2017-03-31

$rank1 = new DateRank($redis,'activity','test', Carbon::now());
$rank2 = new DateRank($redis,'activity','test', Carbon::tomorrow());
$rank1->addRankField(1,2);
$rank1->addRankField(2,4);
$rank2->addRankField(1,2);

$mutliRank = new MutliCounterRank([$rank1,$rank2], $redis);

$rank = new CounterRank($redis, 'activity', 'pager');
$rank->batchAddRankField([
    1 => 2,
    2 => 4,
    3 => 3,
    4 => 20,
    5 => 7,
    6 => 13,
    7 => 10,
    8 => 13,
    9 => 9
]);

$pager = new PagerRank($rank,5,2);