Skip to content

Commit

Permalink
run php-cs-fixer for the src/redis/src
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 7, 2021
1 parent d1c090b commit 82be8fc
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/redis/src/Connection/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
* @method string|array|bool sRandMember(string $key, int $count = null)
* @method array sUnion(string $key1, string $key2, string $keyN = null)
* @method int sUnionStore(string $dstKey, string $key1, string $key2, string $keyN = null)
* @method array|bool scan(int &$iterator, string $pattern = null, int $count = 0)
* @method mixed script(string|array $nodeParams, string $command, string $script)
* @method int setBit(string $key, int $offset, int $value)
* @method string setRange(string $key, int $offset, string $value)
Expand Down Expand Up @@ -255,6 +254,7 @@ public function command(string $method, array $parameters = [], bool $reconnect
Swoft::trigger(RedisEvent::BEFORE_COMMAND, null, $method, $parameters);

Log::profileStart('redis.%s', $method);
/** @see Redis::class */
$result = $this->client->{$method}(...$parameters);
Log::profileEnd('redis.%s', $method);

Expand All @@ -265,10 +265,11 @@ public function command(string $method, array $parameters = [], bool $reconnect
$this->release();
} catch (Throwable $e) {
if (!$reconnect && $this->reconnect()) {
\vdump($e->getMessage(), $this->client->getLastError());
return $this->command($method, $parameters, true);
}

throw new RedisException('Redis command reconnect error=' . $e->getMessage(), $e->getCode(), $e);
throw new RedisException("Redis command exec '$method', error=" . $e->getMessage(), $e->getCode(), $e);
}

return $result;
Expand Down
12 changes: 6 additions & 6 deletions src/redis/src/Connector/PhpRedisConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ public function connect(array $config, array $option): Redis
$client->select($config['database']);
}

if (!empty($config['read_timeout'])) {
$client->setOption(Redis::OPT_READ_TIMEOUT, (string)$config['read_timeout']);
if (isset($config['read_timeout'])) {
$client->setOption(Redis::OPT_READ_TIMEOUT, (int)$config['read_timeout']);
}

if (!empty($option['prefix'])) {
$client->setOption(Redis::OPT_PREFIX, $option['prefix']);
}

if (!empty($option['serializer'])) {
$client->setOption(Redis::OPT_SERIALIZER, (string)$option['serializer']);
if (isset($option['serializer'])) {
$client->setOption(Redis::OPT_SERIALIZER, (int)$option['serializer']);
}

if (!empty($option['scan'])) {
$client->setOption(Redis::OPT_SCAN, (string)$option['scan']);
if (isset($option['scan'])) {
$client->setOption(Redis::OPT_SCAN, (int)$option['scan']);
}

return $client;
Expand Down
1 change: 0 additions & 1 deletion src/redis/src/Redis.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php declare(strict_types=1);


namespace Swoft\Redis;

use Swoft\Bean\BeanFactory;
Expand Down
4 changes: 2 additions & 2 deletions src/redis/src/RedisDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ public function getPassword(): string
*/
public function getRetryInterval(): int
{
return (int)$this->retryInterval;
return $this->retryInterval;
}

/**
* @return int
*/
public function getReadTimeout(): int
{
return (int)$this->readTimeout;
return $this->readTimeout;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/redis/src/RedisEvent.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php declare(strict_types=1);


namespace Swoft\Redis;

/**
Expand All @@ -13,10 +12,10 @@ class RedisEvent
/**
* Before command
*/
const BEFORE_COMMAND = 'swoft.redis.command.before';
public const BEFORE_COMMAND = 'swoft.redis.command.before';

/**
* After command
*/
const AFTER_COMMAND = 'swoft.redis.command.after';
}
public const AFTER_COMMAND = 'swoft.redis.command.after';
}
6 changes: 3 additions & 3 deletions src/redis/test/bean.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
'redis' => [
'class' => \Swoft\Redis\RedisDb::class,
'host' => '127.0.0.1',
'port' => 6379,
'port' => 16379,
'database' => 0,
'retryInterval' => 10,
'readTimeout' => 0,
'timeout' => 2,
'password' => '123$~@456',
// 'password' => '123$~@456',
'driver' => 'phpredis',
'option' => [
'prefix' => 'swoft-t_x',
Expand Down Expand Up @@ -65,7 +65,7 @@
'inc' => [
'class' => \Swoft\Redis\RedisDb::class,
'host' => '127.0.0.1',
'port' => 6379,
'port' => 16379,
'database' => 0,
'retryInterval' => 10,
'readTimeout' => 0,
Expand Down
1 change: 1 addition & 0 deletions src/redis/test/config/redis.php
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<?php
return [];
3 changes: 0 additions & 3 deletions src/redis/test/unit/Command/HashTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php declare(strict_types=1);


namespace SwoftTest\Redis\Unit\Command;


use Swoft\Redis\Redis;
use SwoftTest\Redis\Unit\TestCase;

Expand All @@ -14,7 +12,6 @@
*/
class HashTest extends TestCase
{

public function testhMsetAndhMget()
{
$key = \uniqid();
Expand Down
16 changes: 16 additions & 0 deletions src/redis/test/unit/PoolTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace SwoftTest\Redis\Unit;

/**
* Class PoolTest
*
* @package SwoftTest\Redis\Unit
*/
class PoolTest extends TestCase
{
public function testConnection(): void
{
\vdump(\bean('redis'));
}
}

0 comments on commit 82be8fc

Please sign in to comment.