<?phpclass ranks{const PREFIX = ' Zhengban ';p rotected $redis = ';/* Initialize */public function __construct (Redis $redis) {$th Is->redis = $redis;} /* Added to leaderboard */public function addscores ($gameid, $score) {$key = self::P refix. Date (' Ymd '); return $this->redis-> Zincrby ($key, $score, $gameid);} /* Get leaderboard data for a particular day returns a one-dimensional array, key is Gameid,value is score */public function getonedayrankings ($date, $start, $end) {$key = self:: PREFIX. $date; return $this->redis->zrevrange ($key, $start, $end, true);} /* Get leaderboard for days data */public function getmultidaysrankings ($dates, $start, $end) {$outKey = Null;foreach ($dates as $v) {$keys [] = Self::P refix. $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 "} '); Connection failed}/* auth password */if ($redis->auth ($pwd) = = False) {exit (' {' result ': '-2 '} '); Authentication failed} $Ranks = new ranks ($redis);//$Ranks->addscores (12,1); er = $Ranks->getmultidaysrankings (Array ( 20151021,20151022,20151020), 0,9); Var_dump (er);
Redis leaderboards do your own simple exercises