Skip to content

Commit

Permalink
redis room 初始化数据支持更多的参数
Browse files Browse the repository at this point in the history
其他的一些优化
  • Loading branch information
yunwuxin committed May 26, 2020
1 parent bc53011 commit 61907b8
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 22 deletions.
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"ext-swoole": ">=4.4.8",
"ext-json": "*",
"topthink/framework": "^6.0",
"topthink/think-helper": "^3.0.4",
"symfony/finder": "^4.3.2",
"swoole/ide-helper": "^4.3",
"nette/php-generator": "^3.2",
Expand All @@ -37,7 +36,6 @@
}
}
},
"minimum-stability": "dev",
"require-dev": {
"symfony/var-dumper": "^4.3"
}
Expand Down
3 changes: 2 additions & 1 deletion src/FileWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace think\swoole;

use Swoole\Timer;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

Expand Down Expand Up @@ -34,7 +35,7 @@ public function watch(callable $callback)
{
$this->files = $this->findFiles();

swoole_timer_tick(1000, function () use ($callback) {
Timer::tick(1000, function () use ($callback) {

$files = $this->findFiles();

Expand Down
2 changes: 1 addition & 1 deletion src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Manager

/**
* Manager constructor.
* @param App $container
* @param App $container
* @param PidManager $pidManager
*/
public function __construct(App $container, PidManager $pidManager)
Expand Down
5 changes: 3 additions & 2 deletions src/RpcManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace think\swoole;

use Swoole\Coroutine;
use Swoole\Server;
use Swoole\Server\Port;
use think\App;
Expand Down Expand Up @@ -66,7 +67,7 @@ class RpcManager

/**
* Manager constructor.
* @param App $container
* @param App $container
* @param PidManager $pidManager
*/
public function __construct(App $container, PidManager $pidManager)
Expand Down Expand Up @@ -156,7 +157,7 @@ protected function recv(Server $server, $fd, $data, $callback)
$result = $handle->write($data);

if (!empty($result)) {
go($callback, $result);
Coroutine::create($callback, $result);
$this->channels[$fd]->close();
} else {
$this->channels[$fd]->push($handle);
Expand Down
3 changes: 2 additions & 1 deletion src/concerns/InteractsWithPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace think\swoole\concerns;

use RuntimeException;
use Swoole\Coroutine;
use Swoole\Coroutine\Channel;

trait InteractsWithPool
Expand Down Expand Up @@ -56,7 +57,7 @@ protected function getPoolConnection($name)

protected function wrapProxy(Channel $pool, $connection)
{
defer(function () use ($pool, $connection) {
Coroutine::defer(function () use ($pool, $connection) {
//自动归还
if (!$pool->isFull()) {
$pool->push($connection, 0.001);
Expand Down
5 changes: 3 additions & 2 deletions src/concerns/InteractsWithServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public function run(): void
]);
$this->initialize();
$this->triggerEvent('init');

//热更新
if ($this->getConfig('hot_update.enable', false)) {
//热更新
$this->addHotUpdateProcess();
}

Expand Down Expand Up @@ -163,7 +164,7 @@ protected function addHotUpdateProcess()
});
}, false, 0);

$this->getServer()->addProcess($process);
$this->addProcess($process);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/pool/Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace think\swoole\pool;

use RuntimeException;
use Swoole\Coroutine;
use Swoole\Coroutine\Channel;

abstract class Proxy
Expand Down Expand Up @@ -42,7 +43,7 @@ public function release()

public function __destruct()
{
go(function () {
Coroutine::create(function () {
$this->release();
});
}
Expand Down
5 changes: 3 additions & 2 deletions src/rpc/server/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace think\swoole\rpc\server;

use Swoole\Coroutine;
use think\swoole\rpc\Packer;
use think\swoole\rpc\server\channel\Buffer;
use think\swoole\rpc\server\channel\File;
Expand All @@ -15,9 +16,9 @@ class Channel
public function __construct($header)
{
$this->header = $header;
$this->queue = new \Swoole\Coroutine\Channel(1);
$this->queue = new Coroutine\Channel(1);

go(function () use ($header) {
Coroutine::create(function () use ($header) {
switch ($header['type']) {
case Packer::TYPE_BUFFER:
$type = Buffer::class;
Expand Down
20 changes: 10 additions & 10 deletions src/websocket/room/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Redis implements RoomInterface
* RedisRoom constructor.
*
* @param Manager $manager
* @param array $config
* @param array $config
*/
public function __construct(Manager $manager, array $config)
{
Expand Down Expand Up @@ -73,15 +73,15 @@ protected function prepareRedis()

protected function initData()
{
$host = Arr::get($this->config, 'host', '127.0.0.1');
$port = Arr::get($this->config, 'port', 6379);
$connector = new PhpRedisConnector();

$redis = new PHPRedis();
$redis->connect($host, $port);
if (count($keys = $redis->keys("{$this->prefix}*"))) {
$redis->del($keys);
$connection = $connector->connect($this->config);

if (count($keys = $connection->keys("{$this->prefix}*"))) {
$connection->del($keys);
}
$redis->close();

$connector->disconnect($connection);
}

/**
Expand Down Expand Up @@ -133,7 +133,7 @@ protected function runWithRedis(\Closure $callable)
* Add value to redis.
*
* @param $key
* @param array $values
* @param array $values
* @param string $table
*
* @return $this
Expand All @@ -160,7 +160,7 @@ protected function addValue($key, array $values, string $table)
* Remove value from reddis.
*
* @param $key
* @param array $values
* @param array $values
* @param string $table
*
* @return $this
Expand Down

0 comments on commit 61907b8

Please sign in to comment.