增加MySQL事务处理
This commit is contained in:
parent
fb82505a07
commit
43b509b0ea
|
@ -373,6 +373,16 @@ class Database
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MySQL事务
|
||||||
|
* @param $action
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function transaction($action)
|
||||||
|
{
|
||||||
|
return self::$driver->transaction($action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取最后执行的SQL语句
|
* 获取最后执行的SQL语句
|
||||||
*
|
*
|
||||||
|
|
|
@ -303,6 +303,16 @@ class Model
|
||||||
return $this->getDb()->query($query);
|
return $this->getDb()->query($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MySQL事务
|
||||||
|
* @param $action
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function transaction($action)
|
||||||
|
{
|
||||||
|
return $this->getDb()->transaction($action);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取最后一次执行的SQL
|
* 获取最后一次执行的SQL
|
||||||
*
|
*
|
||||||
|
|
|
@ -70,10 +70,14 @@ class Redis implements CacheIfs
|
||||||
*/
|
*/
|
||||||
public function get($key = null, $callable = null)
|
public function get($key = null, $callable = null)
|
||||||
{
|
{
|
||||||
$value = $this->redis->get($key);
|
$status = $this->exists($key);
|
||||||
|
$value = $status == 0 ? false : $this->redis->get($key);
|
||||||
// 如果获取不到结果但是callable存在
|
// 如果获取不到结果但是callable存在
|
||||||
if ($value === false && is_callable($callable)) {
|
if ($value === false) {
|
||||||
return $callable($this);
|
if (is_callable($callable)) {
|
||||||
|
return $callable($this);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
// 判断值是否是json字符串
|
// 判断值是否是json字符串
|
||||||
$jsonDecode = json_decode($value, true);
|
$jsonDecode = json_decode($value, true);
|
||||||
|
|
|
@ -268,6 +268,25 @@ class MySQLi implements DatabaseIfs
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MySQL事务
|
||||||
|
* @param $action
|
||||||
|
* @return bool
|
||||||
|
* @throws DatabaseException
|
||||||
|
*/
|
||||||
|
public function transaction($action)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->query('start transaction');
|
||||||
|
$action();
|
||||||
|
$this->query('commit');
|
||||||
|
return true;
|
||||||
|
} catch (DatabaseException $e) {
|
||||||
|
$this->query('rollback');
|
||||||
|
throw new DatabaseException($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取执行的最后一条SQL
|
* 获取执行的最后一条SQL
|
||||||
*
|
*
|
||||||
|
|
|
@ -19,9 +19,7 @@ class View implements MiddlewareIfs
|
||||||
$cache = File::instance($config['cacheDir']);
|
$cache = File::instance($config['cacheDir']);
|
||||||
if ($cache->exists($ident)) {
|
if ($cache->exists($ident)) {
|
||||||
$content = $cache->get($ident);
|
$content = $cache->get($ident);
|
||||||
return Response::instance()->header([
|
return Response::instance()->dispatch($content);
|
||||||
'HTTP/1.1 304 Not Modified'
|
|
||||||
])->dispatch($content);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue