yuzuru-s/redis-ranking

Wrapping Redis's sorted set APIs for specializing ranking operations.

1.0.2 2016-11-28 15:26 UTC

This package is not auto-updated.

Last update: 2024-12-21 20:52:27 UTC


README

Coverage Status Build Status Stable Version Download Count License

Abstracting Redis's Sorted Set APIs and PHP to use as a ranking system.

Requirements

Installation

  • Using composer
{
    "require": {
       "yuzuru-s/redis-ranking": "1.0.*"
    }
}
$ php composer.phar update yuzuru-s/redis-ranking --dev

How to use

Please check sample code

<?php
require __DIR__ . '/../vendor/autoload.php';

use YuzuruS\Redis\Ranking;

$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);

$ranking = new Ranking($redis);

$article_ids_of_accessed = [1,1,2,3,4,5,3,4,5,1];


// count up pv of access ids
foreach ($article_ids_of_accessed as $a) {
	$ranking->cntUpPv($a);
}

// make ranking
$ranking->makeAccessRanking(1);

// get ranking
var_dump($ranking->getAccessRanking(1));

/**
array(5) {
[0] =>
string(1) "1"
[1] =>
string(1) "5"
[2] =>
string(1) "4"
[3] =>
string(1) "3"
[4] =>
string(1) "2"
}
 */

How to run unit test

Run with default setting.

% vendor/bin/phpunit -c phpunit.xml.dist

Currently tested with PHP 7.0.0 + Redis 2.6.12.

History

  • 1.0.2
    • Bug fix
  • 1.0.0
    • Published

License

Copyright (c) 2016 YUZURU SUZUKI. See MIT-LICENSE for further details.

Copyright