Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master to feature #247

Merged
merged 35 commits into from
Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2f06f8f
Squashed 'src/task/' changes from e9d76eb8..548e9972
huangzhhui Aug 31, 2018
6d67831
Merge commit '2f06f8fb669be083625740f19715650c3467da4f'
huangzhhui Aug 31, 2018
88481c8
Squashed 'src/session/' changes from e2bc8e6b..be17b6c9
huangzhhui Aug 31, 2018
cb02797
Merge commit '88481c8f50cccc6de6b8309d0daa4498c1240947'
huangzhhui Aug 31, 2018
4e00016
Squashed 'src/rpc-server/' changes from 5622a9ca..525b92ec
huangzhhui Aug 31, 2018
87cfcfc
Merge commit '4e0001669fd6921a9eae6d0aa63edeea01b39851'
huangzhhui Aug 31, 2018
218fee7
Merge branch 'master' of github.com:swoft-cloud/swoft-component
huangzhhui Sep 5, 2018
813e62c
Squashed 'src/console/' changes from 1f3d3cc8..d906edb9
huangzhhui Sep 5, 2018
20a9b6c
Merge commit '813e62c19cf4f3e7f93424072caee3e69ed33336'
huangzhhui Sep 5, 2018
168b76c
Merge branch 'master' of github.com:swoft-cloud/swoft-component
huangzhhui Sep 7, 2018
840c80e
Squashed 'src/auth/' changes from c9bc8780..5aba2468
huangzhhui Sep 7, 2018
9a215bc
Merge commit '840c80eec88d5fcd9680593cfaf27b60c369b415'
huangzhhui Sep 7, 2018
a03aab8
Merge branch 'master' of github.com:swoft-cloud/swoft-component
huangzhhui Sep 12, 2018
1aea625
Merge branch 'master' of github.com:swoft-cloud/swoft-component
huangzhhui Sep 12, 2018
945486b
Merge branch 'master' of github.com:swoft-cloud/swoft-component
huangzhhui Sep 12, 2018
68b5598
Merge branch 'master' of github.com:swoft-cloud/swoft-component
huangzhhui Sep 14, 2018
22eb58a
Merge branch 'master' of github.com:swoft-cloud/swoft-component
huangzhhui Sep 14, 2018
32a7d90
Merge branch 'master' of github.com:swoft-cloud/swoft-component
huangzhhui Oct 17, 2018
834b93d
fix: Temporary fix the data confusion in SessionMiddleware (https://g…
huangzhhui Nov 2, 2018
090a151
fix: Fix Auth token cache time (https://github.com/swoft-cloud/swoft-…
rlgy Nov 2, 2018
0ff126c
feat: Added exclusive lock and shared lock (https://github.com/swoft-…
adotpeng Nov 2, 2018
57c8847
修复 zRem 前缀问题 (https://github.com/swoft-cloud/swoft-component/pull/232)
assert6 Nov 6, 2018
d317122
fix: Fixed Session is accidentally replaced by the next request. (#234)
limingxinleo Nov 7, 2018
99e285b
fix scope usage error (#236)
qin-jd Nov 7, 2018
31482f0
Fixed Session Unit (#235)
limingxinleo Nov 7, 2018
24acf22
FIxed BUG for incorrect result of Redis::HMget and Redis::HGetAll. (#…
limingxinleo Nov 14, 2018
5148097
fix: Fixed after the server is restarted, the client fails to receive…
limingxinleo Nov 15, 2018
41553ce
fix http-client Exception (#238)
wujunze Nov 15, 2018
9412152
optimize: Optimize Server Request initialization. (https://github.com…
huangzhhui Nov 15, 2018
3578f4a
fix: Fixed rpc client log message for exception (#241)
limingxinleo Nov 15, 2018
3d07ee9
fix: Fixed REDIS_DB is not effected when redis reconnected. (#242)
limingxinleo Nov 16, 2018
60f7758
Merge branch 'master' of github.com:swoft-cloud/swoft-component
huangzhhui Nov 21, 2018
96ba462
fix: Fixed unit test (https://github.com/swoft-cloud/swoft-component/…
huangzhhui Nov 21, 2018
9519bfa
feat: Added Redis HyperLogLog (https://github.com/swoft-cloud/swoft-c…
limingxinleo Dec 3, 2018
1880dfb
Merge branch 'master' into feature
limingxinleo Dec 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/db/test/Cases/Mysql/BugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,21 +317,22 @@ public function testListType(int $uid)
/* @var User $user*/
$user = User::findById($uid)->getResult();
$userAry = $user->toArray();

$this->assertTrue(is_int($userAry['age']));
$this->assertTrue(is_int($userAry['sex']));
$this->assertTrue(is_string($userAry['desc']));

/**
* 通过 QueryBuilder 执行的查询将不再格式化结果属性的数据类型
* @see https://github.com/swoft-cloud/swoft-component/pull/209
*/
$row = Query::table(User::class)->where('id', $uid)->one()->getResult();

$this->assertTrue(is_int($row['age']));
$this->assertTrue(is_int($row['sex']));
$this->assertTrue(is_string($row['age']));
$this->assertTrue(is_string($row['sex']));
$this->assertTrue(is_string($row['description']));

$rows = Query::table(User::class)->where('id', $uid)->get()->getResult();
foreach ($rows as $userRow){
$this->assertTrue(is_int($userRow['age']));
$this->assertTrue(is_int($userRow['sex']));
$this->assertTrue(is_string($userRow['age']));
$this->assertTrue(is_string($userRow['sex']));
$this->assertTrue(is_string($userRow['description']));
}
}
Expand Down Expand Up @@ -374,4 +375,4 @@ public function testNoInc()
}


}
}
5 changes: 3 additions & 2 deletions src/http-client/src/Adapter/CoroutineAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Swoft\App;
use Swoft\Helper\JsonHelper;
use Swoft\Http\Message\Uri\Uri;
use Swoft\HttpClient\Exception\RuntimeException;
use Swoft\HttpClient\HttpCoResult;
use Swoft\HttpClient\HttpResultInterface;
use Swoole\Coroutine;
Expand All @@ -30,7 +31,7 @@ class CoroutineAdapter implements AdapterInterface
* @param array $options
* @return HttpResultInterface
* @throws \InvalidArgumentException
* @throws \RuntimeException
* @throws RuntimeException
*/
public function request(RequestInterface $request, array $options = []): HttpResultInterface
{
Expand Down Expand Up @@ -61,7 +62,7 @@ public function request(RequestInterface $request, array $options = []): HttpRes

if (null !== $client->errCode && $client->errCode !== 0) {
App::error(sprintf('HttpClient Request ERROR #%s url=%s', $client->errCode, $url));
throw new \RuntimeException(\socket_strerror($client->errCode), $client->errCode);
throw new RuntimeException(\socket_strerror($client->errCode), $client->errCode);
}

$result = new HttpCoResult(null, $client, $profileKey);
Expand Down
5 changes: 3 additions & 2 deletions src/http-client/src/Adapter/CurlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Psr\Http\Message\RequestInterface;
use Swoft\App;
use Swoft\Helper\JsonHelper;
use Swoft\HttpClient\Exception\RuntimeException;
use Swoft\HttpClient\HttpResult;
use Swoft\HttpClient\HttpResultInterface;

Expand All @@ -25,7 +26,7 @@ class CurlAdapter implements AdapterInterface
* @param array $options
* @return HttpResultInterface
* @throws \InvalidArgumentException
* @throws \RuntimeException
* @throws RuntimeException
*/
public function request(RequestInterface $request, array $options = []): HttpResultInterface
{
Expand Down Expand Up @@ -59,7 +60,7 @@ public function request(RequestInterface $request, array $options = []): HttpRes
$errorString = curl_error($resource);
if ($errorNo) {
App::error(sprintf('HttpClient Request ERROR #%s url=%s', $errorNo, $url));
throw new \RuntimeException($errorString, $errorNo);
throw new RuntimeException($errorString, $errorNo);
}

$result = new HttpResult($result);
Expand Down
13 changes: 7 additions & 6 deletions src/http-message/src/Server/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ public static function loadFromSwooleRequest(\Swoole\Http\Request $swooleRequest
$body = new SwooleStream($swooleRequest->rawContent());
$protocol = isset($server['server_protocol']) ? str_replace('HTTP/', '', $server['server_protocol']) : '1.1';
$request = new static($method, $uri, $headers, $body, $protocol);
return $request->withCookieParams($swooleRequest->cookie ?? [])
->withQueryParams($swooleRequest->get ?? [])
->withServerParams($server ?? [])
->withParsedBody($swooleRequest->post ?? [])
->withUploadedFiles(self::normalizeFiles($swooleRequest->files ?? []))
->setSwooleRequest($swooleRequest);
$request->cookieParams = ($swooleRequest->cookie ?? []);
$request->queryParams = ($swooleRequest->get ?? []);
$request->serverParams = ($server ?? []);
$request->parsedBody = ($swooleRequest->post ?? []);
$request->uploadedFiles = self::normalizeFiles($swooleRequest->files ?? []);
$request->swooleRequest = $swooleRequest;
return $request;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/redis/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
install:
- wget https://github.com/redis/hiredis/archive/v0.13.3.tar.gz -O hiredis.tar.gz && mkdir -p hiredis && tar -xf hiredis.tar.gz -C hiredis --strip-components=1 && cd hiredis && sudo make -j$(nproc) && sudo make install && sudo ldconfig && cd ..
- echo 'no' | pecl install -f redis
- wget https://github.com/swoole/swoole-src/archive/v4.0.2.tar.gz -O swoole.tar.gz && mkdir -p swoole && tar -xf swoole.tar.gz -C swoole --strip-components=1 && rm swoole.tar.gz && cd swoole && phpize && ./configure --enable-async-redis && make -j$(nproc) && make install && cd -
- wget https://github.com/swoole/swoole-src/archive/v4.2.9.tar.gz -O swoole.tar.gz && mkdir -p swoole && tar -xf swoole.tar.gz -C swoole --strip-components=1 && rm swoole.tar.gz && cd swoole && phpize && ./configure --enable-async-redis && make -j$(nproc) && make install && cd -
- echo "extension = swoole.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini

before_script:
Expand Down
4 changes: 0 additions & 4 deletions src/redis/src/AbstractRedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ protected function initRedis()
$error = sprintf('Redis connection authentication failed host=%s port=%d auth=%s', $host, (int)$port, (string)$config['auth']);
throw new RedisException($error);
}
if (isset($config['database']) && $config['database'] < 16 && false === $redis->select($config['database'])) {
$error = sprintf('Redis selection database failure host=%s port=%d database=%d', $host, (int)$port, (int)$config['database']);
throw new RedisException($error);
}

return $redis;
}
Expand Down
5 changes: 4 additions & 1 deletion src/redis/src/Operator/Hashes/HashGetAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ public function getId()
*/
public function parseResponse($data)
{
$result = array();
if ($data === false) {
return false;
}

$result = [];
for ($i = 0; $i < count($data); ++$i) {
$result[$data[$i]] = $data[++$i];
}
Expand Down
6 changes: 5 additions & 1 deletion src/redis/src/Operator/Hashes/HashGetMultiple.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ public function getId()
*/
public function parseResponse($data)
{
if ($data === false) {
return false;
}

$result = [];
$hashKeys = $this->getArgument(1);
foreach ($data as $key => $value) {
if (! isset($hashKeys[$key])) {
if (!isset($hashKeys[$key])) {
continue;
}

Expand Down
44 changes: 44 additions & 0 deletions src/redis/src/Operator/Processor/PrefixProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Swoft\Redis\Operator\Processor;

use Swoft\Bean\Annotation\Inject;
use Swoft\Helper\StringHelper;
use Swoft\Redis\Operator\CommandInterface;
use Swoft\Bean\Annotation\Bean;
use Swoft\Redis\Pool\Config\RedisPoolConfig;
Expand Down Expand Up @@ -95,6 +96,7 @@ public function init()
'ZADD' => 'static::first',
'ZINCRBY' => 'static::first',
'ZREM' => 'static::first',
'ZDELETE' => 'static::first',
'ZRANGE' => 'static::first',
'ZREVRANGE' => 'static::first',
'ZRANGEBYSCORE' => 'static::first',
Expand Down Expand Up @@ -149,6 +151,10 @@ public function init()
'EVALSHA' => 'static::evalKeys',
'ZRANGEBYLEX' => 'static::first',
'ZREVRANGEBYLEX' => 'static::first',
'PFADD' => 'static::first',
'PFCOUNT' => 'static::allarray',
'PFMERGE' => 'static::allarray',
'ZINTER' => 'static::allarray2',
];
}

Expand Down Expand Up @@ -257,6 +263,33 @@ public static function all(CommandInterface $command, $prefix)
}
}

/**
* Applies the specified prefix to all the arguments.
*
* @param CommandInterface $command Command instance.
* @param string $prefix Prefix string.
*/
public static function allarray(CommandInterface $command, $prefix, $len = 0)
{
if ($arguments = $command->getArguments()) {
$result = [];
foreach ($arguments as $index => $key) {
if ($len > 0 && $index >= $len) {
$result[] = $key;
} elseif (is_array($key)) {
foreach ($key as &$i) {
$i = "$prefix$i";
}
$result[] = $key;
} else {
$result[] = "$prefix$key";
}
}

$command->setRawArguments($result);
}
}

/**
* Applies the specified prefix only to even arguments in the list.
*
Expand Down Expand Up @@ -384,4 +417,15 @@ public static function zsetStore(CommandInterface $command, $prefix)
$command->setRawArguments($arguments);
}
}

public static function __callStatic($name, $arguments)
{
if (StringHelper::startsWith($name, 'allarray')) {
$len = (int)StringHelper::replaceFirst('allarray', '', $name);
$arguments[] = $len;
return static::allarray(...$arguments);
}

throw new \Exception("class 'Swoft\Redis\Operator\Processor\PrefixProcessor' does not have a method '{$name}'");
}
}
19 changes: 19 additions & 0 deletions src/redis/src/Operator/Strings/StringPfAdd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php


namespace Swoft\Redis\Operator\Strings;

use Swoft\Redis\Operator\Command;

class StringPfAdd extends Command
{
/**
* [String] pfAdd
*
* @return string
*/
public function getId()
{
return 'pfAdd';
}
}
19 changes: 19 additions & 0 deletions src/redis/src/Operator/Strings/StringPfCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php


namespace Swoft\Redis\Operator\Strings;

use Swoft\Redis\Operator\Command;

class StringPfCount extends Command
{
/**
* [String] pfCount
*
* @return string
*/
public function getId()
{
return 'pfCount';
}
}
19 changes: 19 additions & 0 deletions src/redis/src/Operator/Strings/StringPfMerge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php


namespace Swoft\Redis\Operator\Strings;

use Swoft\Redis\Operator\Command;

class StringPfMerge extends Command
{
/**
* [String] pfMerge
*
* @return string
*/
public function getId()
{
return 'pfMerge';
}
}
13 changes: 13 additions & 0 deletions src/redis/src/Operator/ZSets/ZSetInterStore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Swoft\Redis\Operator\ZSets;

use Swoft\Redis\Operator\Command;

class ZSetInterStore extends Command
{
public function getId()
{
return 'ZInter';
}
}
3 changes: 0 additions & 3 deletions src/redis/src/Pool/RedisPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public function createConnection(): ConnectionInterface
$redis = new SyncRedisConnection($this);
}

$dbIndex = $this->poolConfig->getDb();
$redis->select($dbIndex);

return $redis;
}
}
5 changes: 5 additions & 0 deletions src/redis/src/Profile/RedisCommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public function getSupportedCommands(): array
'INCRBYFLOAT' => '\Swoft\Redis\Operator\Strings\StringIncrementByFloat',
'BITOP' => '\Swoft\Redis\Operator\Strings\StringBitOp',
'BITCOUNT' => '\Swoft\Redis\Operator\Strings\StringBitCount',
/* ---------------- Redis 2.8 ---------------- */
'PFADD' => '\Swoft\Redis\Operator\Strings\StringPfAdd',
'PFCOUNT' => '\Swoft\Redis\Operator\Strings\StringPfCount',
'PFMERGE' => '\Swoft\Redis\Operator\Strings\StringPfMerge',

/* commands operating on lists */
/* ---------------- Redis 1.2 ---------------- */
Expand Down Expand Up @@ -146,6 +150,7 @@ public function getSupportedCommands(): array
'ZREVRANK' => '\Swoft\Redis\Operator\ZSets\ZSetReverseRank',
'ZREMRANGEBYRANK' => '\Swoft\Redis\Operator\ZSets\ZSetRemoveRangeByRank',
'ZDELETERANGEBYRANK' => '\Swoft\Redis\Operator\ZSets\ZSetRemoveRangeByRank',
'ZINTER' => '\Swoft\Redis\Operator\ZSets\ZSetInterStore',
/* ---------------- Redis 2.2 ---------------- */
'ZREVRANGEBYSCORE' => '\Swoft\Redis\Operator\ZSets\ZSetReverseRangeByScore',
/* ---------------- Redis 2.8 ---------------- */
Expand Down
4 changes: 4 additions & 0 deletions src/redis/src/RedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function createConnection()
{
$redis = $this->initRedis();
$this->connection = $redis;

/** @var RedisPoolConfig $config */
$config = $this->getPool()->getPoolConfig();
$redis->select($config->getDb());
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/redis/src/SyncRedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function createConnection()
$redis->setOption(\Redis::OPT_PREFIX, $prefix);
}
$this->connection = $redis;

/** @var RedisPoolConfig $config */
$config = $this->getPool()->getPoolConfig();
$redis->select($config->getDb());
}

/**
Expand Down
Loading