From ee255c02f9018fa57eba548f4781f5ef02ae84c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 29 Jun 2021 12:01:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/Command.php | 6 ++++++ System/Cache/Redis.php | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Database/Command.php b/Database/Command.php index 2817c7ed..c015f4d6 100644 --- a/Database/Command.php +++ b/Database/Command.php @@ -14,6 +14,7 @@ use Exception; use PDO; use PDOStatement; use Snowflake\Abstracts\Component; +use Snowflake\Core\Json; /** * Class Command @@ -121,11 +122,16 @@ class Command extends Component { try { $this->debug('Execute: ' . $this->sql); + + $time = microtime(true); if ($type === static::EXECUTE) { $result = $this->insert_or_change($isInsert, $hasAutoIncrement); } else { $result = $this->search($type); } + if (microtime(true) - $time >= 0.02) { + $this->debug('Mysql:' . Json::encode([$this->sql, $this->params])); + } if ($this->prepare) { $this->prepare->closeCursor(); } diff --git a/System/Cache/Redis.php b/System/Cache/Redis.php index ecb8634e..88f5e757 100644 --- a/System/Cache/Redis.php +++ b/System/Cache/Redis.php @@ -12,6 +12,7 @@ namespace Snowflake\Cache; use Exception; use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Config; +use Snowflake\Core\Json; use Snowflake\Event; use Snowflake\Exception\ConfigException; use Snowflake\Snowflake; @@ -20,7 +21,7 @@ use Snowflake\Snowflake; * Class Redis * @package Snowflake\Snowflake\Cache * @see \Redis - * + * */ class Redis extends Component { @@ -68,11 +69,17 @@ class Redis extends Component */ public function __call($name, $arguments): mixed { + $time = microtime(true); if (method_exists($this, $name)) { $data = $this->{$name}(...$arguments); } else { $data = $this->proxy()->{$name}(...$arguments); } + + if (microtime(true) - $time >= 0.02) { + $this->debug('Redis:' . Json::encode([$name, $arguments])); + } + return $data; } @@ -83,7 +90,7 @@ class Redis extends Component * @return bool|int * @throws Exception */ - public function lock($key, $timeout = 5): bool|int + public function lock($key, int $timeout = 5): bool|int { $script = <<