Redis 熱門排行榜 自己簡單練習

來源:互聯網
上載者:User

標籤:初始化   efi   redis   簡單   log   his   host   prot   cti   

<?phpclass Ranks{const PREFIX = ‘zhengban‘;protected $redis = ‘‘;/*初始化 */public function __construct(redis $redis){$this->redis = $redis;}/*添加到熱門排行榜 */public function addScores($gameid,$score){$key = self::PREFIX . date(‘Ymd‘);return $this->redis->zIncrBy($key, $score, $gameid);}/*擷取特定一天的熱門排行榜資料返回一維數組,key是gameid,value是score */public function getOneDayRankings($date,$start,$end){$key = self::PREFIX . $date;        return $this->redis->zRevRange($key, $start, $end, true);}/*擷取幾天資料的熱門排行榜 */public function getMultiDaysRankings($dates,$start,$end){$outKey = null;foreach ($dates as $v){$keys[] = self::PREFIX . $v;}        //$weights = array_fill(0, count($keys), 1);        //$this->redis->zUnion($outKey, $keys,$weights);        $this->redis->zUnion($outKey, $keys);        return $this->redis->zRevRange($outKey, $start, $end, true);}}$host = "192.168.1.114";$port = 6379;$pwd = "123456";$redis = new Redis();if ($redis->connect($host, $port) == false) {exit(‘{"result":"-1"}‘);   //串連失敗}/* AUTH的密碼 */if ($redis->auth($pwd) == false) {exit(‘{"result":"-2"}‘);   //認證失敗}$Ranks = new Ranks($redis);//$Ranks->addScores(12,1);$order = $Ranks->getMultiDaysRankings(array(20151021,20151022,20151020),0,9);var_dump($order);

 

Redis 熱門排行榜 自己簡單練習

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.