Ejemplo n.º 1
0
 /**
  * 获取阅读量
  * @return number
  */
 public function getView()
 {
     $key = 'question_view';
     $redis = new Redis();
     $view = $redis->zScore($key, 'question:' . $this->id);
     if ($view) {
         return $view;
     }
     return 0;
 }
Ejemplo n.º 2
0
 /**
  * 获取活跃用户
  * @param int $limit
  */
 public function getActives($limit = 5)
 {
     $redis = new Redis();
     $key = 'user_login';
     $result = $redis->zrevrange($key, 0, $limit);
     $users = array();
     foreach ($result as $value) {
         $user_id = explode(':', $value)[1];
         $user = $this->get($user_id);
         if ($user) {
             $users[] = $user;
         }
     }
     return $users;
 }