for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @filename LoginStatistics.php
* @touch 09/11/2016 16:28
* @author wudege <[email protected]>
* @version 1.0.0
*/
namespace TokenAssistant;
use Predis\Client;
class LoginStatistics implements LoginStatisticsInterface
{
const USER_STAT_SORTED_SET_NAMESPACE = 'user-stat:';
* @var Client
private $redisClient;
public function __construct(Client $client)
$this->redisClient = $client;
}
*
* @param int $startTimestamp
* @param int $endTimestamp
* @return int
public function countUsers($startTimestamp, $endTimestamp)
return $this->redisClient->zcount(static::USER_STAT_SORTED_SET_NAMESPACE, $startTimestamp, $endTimestamp);
* @param $startTimestamp
* @param $endTimestamp
* @return array
public function listUsers($startTimestamp, $endTimestamp)
return $this->redisClient->zrevrangebyscore(static::USER_STAT_SORTED_SET_NAMESPACE, $endTimestamp, $startTimestamp);
* @param string $userId
* @param int $timestamp
* @return bool
public function refresh($userId, $timestamp)
$this->redisClient->zadd(static::USER_STAT_SORTED_SET_NAMESPACE, array($userId => $timestamp));
return true;
* @param $userId
* @return string
public function lastVisited($userId)
return $this->redisClient->zscore(static::USER_STAT_SORTED_SET_NAMESPACE, $userId);