diff --git a/framework/library/Database.php b/framework/library/Database.php index 6b3b8ad..a8136d3 100644 --- a/framework/library/Database.php +++ b/framework/library/Database.php @@ -373,6 +373,16 @@ class Database return $result; } + /** + * MySQL事务 + * @param $action + * @return mixed + */ + public function transaction($action) + { + return self::$driver->transaction($action); + } + /** * 获取最后执行的SQL语句 * diff --git a/framework/library/Model.php b/framework/library/Model.php index d97d736..f7dae76 100644 --- a/framework/library/Model.php +++ b/framework/library/Model.php @@ -303,6 +303,16 @@ class Model return $this->getDb()->query($query); } + /** + * MySQL事务 + * @param $action + * @return mixed + */ + public function transaction($action) + { + return $this->getDb()->transaction($action); + } + /** * 获取最后一次执行的SQL * diff --git a/framework/library/cache/driver/Redis.php b/framework/library/cache/driver/Redis.php index 2990ac4..0534a23 100644 --- a/framework/library/cache/driver/Redis.php +++ b/framework/library/cache/driver/Redis.php @@ -70,10 +70,14 @@ class Redis implements CacheIfs */ 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存在 - if ($value === false && is_callable($callable)) { - return $callable($this); + if ($value === false) { + if (is_callable($callable)) { + return $callable($this); + } + return false; } // 判断值是否是json字符串 $jsonDecode = json_decode($value, true); diff --git a/framework/library/database/driver/MySQLi.php b/framework/library/database/driver/MySQLi.php index 12189ca..55c4e0b 100644 --- a/framework/library/database/driver/MySQLi.php +++ b/framework/library/database/driver/MySQLi.php @@ -268,6 +268,25 @@ class MySQLi implements DatabaseIfs 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 * diff --git a/framework/middleware/View.php b/framework/middleware/View.php index aabf713..5eda809 100644 --- a/framework/middleware/View.php +++ b/framework/middleware/View.php @@ -19,9 +19,7 @@ class View implements MiddlewareIfs $cache = File::instance($config['cacheDir']); if ($cache->exists($ident)) { $content = $cache->get($ident); - return Response::instance()->header([ - 'HTTP/1.1 304 Not Modified' - ])->dispatch($content); + return Response::instance()->dispatch($content); } } return true;