From 154fe2905a03c81184c03b0c924d188a8e651945 Mon Sep 17 00:00:00 2001 From: lifinsky Date: Mon, 9 Nov 2020 17:21:40 +0200 Subject: [PATCH 1/3] Improve PhpRedisConnector class: add auth option (username and password). --- src/redis/src/Connector/PhpRedisConnector.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/redis/src/Connector/PhpRedisConnector.php b/src/redis/src/Connector/PhpRedisConnector.php index 9bcd424c1..a9352942d 100644 --- a/src/redis/src/Connector/PhpRedisConnector.php +++ b/src/redis/src/Connector/PhpRedisConnector.php @@ -30,6 +30,11 @@ class PhpRedisConnector implements ConnectorInterface */ public function connect(array $config, array $option): Redis { + if (isset($option['auth'])) { + $config['auth'] = $option['auth']; + unset($option['auth']); + } + $client = new Redis(); $this->establishConnection($client, $config); @@ -159,12 +164,17 @@ protected function establishConnection(Redis $client, array $config): void $config['host'], $config['port'], $config['timeout'], - '', + null, $config['retry_interval'], ]; - if (version_compare(phpversion('redis'), '3.1.3', '>=')) { + $redisVersion = \phpversion('redis'); + if (\version_compare($redisVersion, '3.1.3', '>=')) { $parameters[] = $config['read_timeout']; + + if (!empty($config['auth']) && \version_compare($redisVersion, '3.5', '>=')) { + $parameters[] = ['auth' => $config['auth']]; + } } $result = $client->connect(...$parameters); From d663c210429d59a5c21794dd32d9ba1d2dfec8b8 Mon Sep 17 00:00:00 2001 From: lifinsky Date: Tue, 24 Nov 2020 11:55:49 +0200 Subject: [PATCH 2/3] Improve SwoftTest\Http\Server\Testing\MockResponse::cookie() method: Swoole 4.5.8. Use swoole/ide-helper library because swoft/swoole-ide-helper is too old. --- composer.json | 2 +- src/http-server/test/testing/MockResponse.php | 36 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index b75d39e15..7355e33c9 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ }, "require-dev": { "phpunit/phpunit": "^7.5", - "swoft/swoole-ide-helper": "dev-master" + "swoole/ide-helper": "dev-master" }, "replace": { "swoft/annotation": "self.version", diff --git a/src/http-server/test/testing/MockResponse.php b/src/http-server/test/testing/MockResponse.php index 3a3c1eab5..0983cb97f 100644 --- a/src/http-server/test/testing/MockResponse.php +++ b/src/http-server/test/testing/MockResponse.php @@ -80,14 +80,15 @@ public function header($key, $value, $ucwords = null) } /** - * @param string $name - * @param string $value - * @param int|string $expires - * @param string|null $path - * @param string $domain - * @param bool $secure - * @param bool $httpOnly - * @param null $samesite + * @param string $name + * @param string|null $value + * @param int|string|null $expires + * @param string|null $path + * @param string|null $domain + * @param bool|null $secure + * @param bool|null $httpOnly + * @param string|null $samesite + * @param string|null $priority */ public function cookie( $name, @@ -97,7 +98,8 @@ public function cookie( $domain = null, $secure = null, $httpOnly = null, - $samesite = null + $samesite = null, + $priority = null ) { $result = \urlencode($name) . '=' . \urlencode($value); @@ -117,22 +119,26 @@ public function cookie( } if ($timestamp !== 0) { - $result .= '; expires=' . \gmdate('D, d-M-Y H:i:s e', $timestamp); + $result .= '; Expires=' . \gmdate('D, d-M-Y H:i:s e', $timestamp); } } if ($secure) { - $result .= '; secure'; + $result .= '; Secure'; } - // if ($hostOnly) { - // $result .= '; HostOnly'; - // } - if ($httpOnly) { $result .= '; HttpOnly'; } + if ($samesite) { + $result .= '; SameSite=' . $samesite; + } + + if ($priority) { + $result .= '; Priority=' . $priority; + } + $this->cookie[$name] = $result; } From 242aea3a1bb42e93a22d6bf58e4e2b6c24a689e9 Mon Sep 17 00:00:00 2001 From: Inhere Date: Tue, 5 Jan 2021 10:29:02 +0800 Subject: [PATCH 3/3] trigger ci build tests --- src/redis/src/Connector/PhpRedisConnector.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/redis/src/Connector/PhpRedisConnector.php b/src/redis/src/Connector/PhpRedisConnector.php index a9352942d..0433979dd 100644 --- a/src/redis/src/Connector/PhpRedisConnector.php +++ b/src/redis/src/Connector/PhpRedisConnector.php @@ -11,6 +11,7 @@ use Swoft\Redis\Exception\RedisException; use Swoft\Stdlib\Helper\Arr; use Swoft\Stdlib\Helper\JsonHelper; +use function version_compare; /** * Class PhpRedisConnector