/** * 批量设置键值(当键名不存在时);<br> * 只有当键值全部设置成功时,才返回true,否则返回false并尝试回滚 * @param array $sets 键值数组 * @return boolean 是否成功 */ public function mSetNX($sets) { try { $keys = []; $status = true; foreach ($sets as $key => $value) { $status = $this->handler->setnx($key, self::setValue($value)); if ($status) { $keys[] = $key; } else { break; } } //如果失败,尝试回滚,但不保证成功 if (!$status) { foreach ($keys as $key) { $this->handler->del($key); } } return (bool) $status; } catch (SSDBException $ex) { self::exception($ex); //连接状态置为false $this->isConnected = false; } return false; }