예제 #1
0
 /**
  * 批量设置键值
  * @param array $sets   键值数组
  * @return boolean      是否成功
  */
 public function mSet($sets)
 {
     if ($this->driver->checkDriver()) {
         if (method_exists($this->driver, 'mSet')) {
             return $this->driver->mSet($sets);
         } else {
             $oldSets = [];
             $status = true;
             foreach ($sets as $key => $value) {
                 $oldSets[$key] = $this->driver->get($key);
                 $status = $this->driver->set($key, $value);
                 if (!$status) {
                     break;
                 }
             }
             //如果失败,尝试回滚,但不保证成功
             if (!$status) {
                 foreach ($oldSets as $key => $value) {
                     if ($value === false) {
                         $this->driver->del($key);
                     } else {
                         $this->driver->set($key, $value);
                     }
                 }
             }
             return $status;
         }
     }
     if ($this->driver->isFallback() && $this->type !== self::$config['fallback']) {
         return $this->driver->backup()->mSet($sets);
     }
     return false;
 }