Example #1
0
 /**
  * 保存一条数据
  */
 public static function save($paramArr)
 {
     $options = array('server' => 'localhost', 'db' => false, 'collection' => false, 'key' => false, 'value' => false);
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     return API_MongoDB::save($server, $db, $collection, $key, $value);
 }
Example #2
0
 /**
  * 设置缓存数据
  */
 public static function set($paramArr)
 {
     $options = array('module' => false, 'tbl' => 'tbl', 'key' => false, 'data' => false, 'meta' => false, 'life' => 0, 'retry' => true);
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     if (!$module || !isset(self::$_cacheCfg[$module])) {
         return false;
     }
     $cfg = self::$_cacheCfg[$module]["write"];
     $ttlFlag = isset(self::$_cacheCfg[$module]['ttl']) && self::$_cacheCfg[$module]['ttl'] ? true : false;
     //是否开启TTL
     #服务器数据
     $server = $cfg["server"];
     $db = $module;
     $md5key = md5($key);
     $tbl = $tbl ? $tbl : "tbl";
     $collection = $tbl . '_' . substr($md5key, 0, 2);
     $data = array('key' => $key, 'data' => $data, 'life' => $life ? $life + SYSTEM_TIME : 0);
     //设置TTL的时间
     if ($ttlFlag) {
         $data['ttldt'] = new MongoDate(SYSTEM_TIME);
     }
     if ($meta) {
         $data['meta'] = $meta;
     }
     try {
         API_MongoDB::save($server, $db, $collection, $md5key, $data);
     } catch (Exception $e) {
         if (!empty($options['retry'])) {
             $options['retry'] = false;
             self::set($options);
         }
     }
     return true;
 }