This commit is contained in:
2021-06-29 12:01:06 +08:00
parent e4c65484fe
commit ee255c02f9
2 changed files with 15 additions and 2 deletions
+6
View File
@@ -14,6 +14,7 @@ use Exception;
use PDO; use PDO;
use PDOStatement; use PDOStatement;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use Snowflake\Core\Json;
/** /**
* Class Command * Class Command
@@ -121,11 +122,16 @@ class Command extends Component
{ {
try { try {
$this->debug('Execute: ' . $this->sql); $this->debug('Execute: ' . $this->sql);
$time = microtime(true);
if ($type === static::EXECUTE) { if ($type === static::EXECUTE) {
$result = $this->insert_or_change($isInsert, $hasAutoIncrement); $result = $this->insert_or_change($isInsert, $hasAutoIncrement);
} else { } else {
$result = $this->search($type); $result = $this->search($type);
} }
if (microtime(true) - $time >= 0.02) {
$this->debug('Mysql:' . Json::encode([$this->sql, $this->params]));
}
if ($this->prepare) { if ($this->prepare) {
$this->prepare->closeCursor(); $this->prepare->closeCursor();
} }
+8 -1
View File
@@ -12,6 +12,7 @@ namespace Snowflake\Cache;
use Exception; use Exception;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use Snowflake\Abstracts\Config; use Snowflake\Abstracts\Config;
use Snowflake\Core\Json;
use Snowflake\Event; use Snowflake\Event;
use Snowflake\Exception\ConfigException; use Snowflake\Exception\ConfigException;
use Snowflake\Snowflake; use Snowflake\Snowflake;
@@ -68,11 +69,17 @@ class Redis extends Component
*/ */
public function __call($name, $arguments): mixed public function __call($name, $arguments): mixed
{ {
$time = microtime(true);
if (method_exists($this, $name)) { if (method_exists($this, $name)) {
$data = $this->{$name}(...$arguments); $data = $this->{$name}(...$arguments);
} else { } else {
$data = $this->proxy()->{$name}(...$arguments); $data = $this->proxy()->{$name}(...$arguments);
} }
if (microtime(true) - $time >= 0.02) {
$this->debug('Redis:' . Json::encode([$name, $arguments]));
}
return $data; return $data;
} }
@@ -83,7 +90,7 @@ class Redis extends Component
* @return bool|int * @return bool|int
* @throws Exception * @throws Exception
*/ */
public function lock($key, $timeout = 5): bool|int public function lock($key, int $timeout = 5): bool|int
{ {
$script = <<<SCRIPT $script = <<<SCRIPT
local _nx = redis.call('setnx',KEYS[1], ARGV[1]) local _nx = redis.call('setnx',KEYS[1], ARGV[1])