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 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