Esempio n. 1
0
 /**
  * 获得一条数据
  */
 public static function findOne($paramArr)
 {
     $options = array('server' => 'localhost', 'db' => false, 'collection' => false, 'key' => false);
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     return API_MongoDB::findOne($server, $db, $collection, $key);
 }
Esempio n. 2
0
 /**
  * 获得缓存数据
  */
 public static function get($paramArr)
 {
     $options = array('module' => false, 'tbl' => 'tbl', 'key' => false, 'getMeta' => false, 'write' => false, 'minTm' => 0, 'retry' => true);
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     if (!$module || !isset(self::$_cacheCfg[$module])) {
         return false;
     }
     $cfg = $write ? self::$_cacheCfg[$module]["write"] : self::$_cacheCfg[$module]["read"];
     $extParam = array();
     if (isset($cfg["slaveOk"])) {
         $extParam['slaveOkay'] = 1;
     }
     if ($write) {
         $extParam['slaveOkay'] = 0;
     }
     #服务器数据
     $server = $cfg["server"];
     $db = $module;
     $md5key = md5($key);
     $tbl = $tbl ? $tbl : "tbl";
     $collection = $tbl . '_' . substr($md5key, 0, 2);
     #获得数据
     try {
         $data = API_MongoDB::findOne($server, $db, $collection, $md5key, $extParam);
     } catch (Exception $e) {
         if (!empty($options['retry'])) {
             $options['retry'] = false;
             return self::get($options);
         }
     }
     $out = false;
     if (isset($data) && $data && isset($data['data'])) {
         #判断有效期,如果已经过期了,就返回false
         if (!isset($data['life']) || !$data['life'] || $data['life'] > SYSTEM_TIME) {
             $out = $data['data'];
             if ($minTm && $data['life'] < $minTm) {
                 $out = false;
             }
             if ($getMeta) {
                 $out = array('data' => $data['data'], 'meta' => isset($data['meta']) ? $data['meta'] : false);
             }
         }
     }
     return $out;
 }