/**
  * 
  * @brief 最新发布的文章,默认存放50条
  * @param int $type
  * @param int $majory
  * @param int $limit
  */
 public static function getNewArticle($majoryId, $limit = 10, $offset = 0)
 {
     $limit = $limit < 51 ? $limit : 50;
     $key = 'new_' . $majoryId;
     //list时间默认5分钟;
     $t = getMicrosecond();
     $result = DBRedis::lRange($key, $offset, $limit + $offset - 1, self::$_TIME);
     if ($result) {
         return array_map('unserialize', $result);
     } else {
         //echo 'new mysql/';
         $sql = self::_buildSql($majoryId, 'new');
         $result = DBMysqli::getInstance()->getAll($sql);
         foreach ($result as $value) {
             DBRedis::rPush($key, serialize($value));
         }
         //            echo $sql.' -> '.((getMicrosecond()-$t)/1000).'<br>';
         return array_slice($result, 0, $limit);
     }
 }
Esempio n. 2
0
 private static function _checkPort()
 {
     $t = getMicrosecond();
     try {
         $fp = fsockopen(DBConfig::$REDIS['host'], DBConfig::$REDIS['port'], $errno, $errstr, 0.1);
     } catch (Exception $e) {
         return false;
     }
     if ($fp) {
         fclose($fp);
         return true;
     }
     return false;
 }