From eed39e3feadaed493895d7baf052453bff6fc5e3 Mon Sep 17 00:00:00 2001 From: tangxuliang <1297441127@qq.com> Date: Thu, 24 Mar 2022 16:08:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20redis=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=AF=BB=E5=8F=96env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Redis.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Redis.php b/src/Redis.php index c78d567..fd8bce3 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -18,16 +18,24 @@ public function __construct(array $config = []) $this->type = 'string'; $this->score = 0; $this->expire = -1; + + $options = [ + 'parameters' => [ + 'password' => $config['password'] ?? getenv('REDIS_PASSWORD') ?? '', + 'database' => $config['database'] ?? getenv('REDIS_DB') ?? 0, + ], + ]; $this->client = new Client([ 'scheme' => 'tcp', - 'host' => $config['host'] ?? '127.0.0.1', - 'port' => $config['port'] ?? 6379, - ]); + 'host' => $config['host'] ?? getenv('REDIS_HOST') ?? '127.0.0.1', + 'port' => $config['port'] ?? getenv('REDIS_PORT') ?? 6379, + ], $options); } /** * 调用predis方法. * + * @param string $name * @param array $arguments */ public function __call(string $name, array $arguments): void From a464b5c140d9434a0e5438913e70e87ae81a53d3 Mon Sep 17 00:00:00 2001 From: Teakowa Gatanothor O'deorain Date: Thu, 24 Mar 2022 16:13:00 +0800 Subject: [PATCH 2/2] chore: add testing Signed-off-by: Teakowa Gatanothor O'deorain --- .env.testing | 3 +++ .github/workflows/tests.yml | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 .env.testing diff --git a/.env.testing b/.env.testing new file mode 100644 index 0000000..48a4eed --- /dev/null +++ b/.env.testing @@ -0,0 +1,3 @@ +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD= +REDIS_PORT=6379 \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c3ece4f..4ad38c8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -89,10 +89,15 @@ jobs: - name: Prepare for environment variables run: | + cp .env.testing .env composer dump-autoload - name: Run Testsuite run: vendor/bin/pest tests/ --coverage-text --colors=always --coverage-html=coverage --coverage-clover coverage.xml + env: + REDIS_HOST: 127.0.0.1 + REDIS_PASSWORD: + REDIS_PORT: 6379 - name: Upload coverage to Codecov uses: codecov/codecov-action@v2