Skip to content

Commit

Permalink
Merge pull request #33 from gaobinzhan/4.x
Browse files Browse the repository at this point in the history
up: redis pool restriction
  • Loading branch information
kiss291323003 authored Jan 5, 2021
2 parents d8f949b + e434cc3 commit b04f236
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"easyswoole/spl": "^1.0",
"easyswoole/utility": "^1.0",
"easyswoole/component": "^2.0",
"easyswoole/redis-pool": "^2.0"
"easyswoole/redis-pool": "~2.1.0"
},
"require-dev": {
"easyswoole/swoole-ide-helper": "^1.1"
Expand Down
5 changes: 5 additions & 0 deletions src/NodeManager/RedisManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace EasySwoole\Rpc\NodeManager;

use EasySwoole\Redis\Redis;
use EasySwoole\RedisPool\RedisPool;
use EasySwoole\Rpc\ServiceNode;
use EasySwoole\Utility\Random;
Expand All @@ -20,6 +21,7 @@ function __construct(RedisPool $pool, string $hashKey = 'rpc')

function getServiceNodes(string $serviceName, ?string $version = null): array
{
/** @var Redis $redis */
$redis = $this->pool->getObj(15);
try {
$nodes = $redis->hGetAll("{$this->redisKey}_{$serviceName}");
Expand Down Expand Up @@ -60,6 +62,7 @@ function getServiceNode(string $serviceName, ?string $version = null): ?ServiceN

function deleteServiceNode(ServiceNode $serviceNode): bool
{
/** @var Redis $redis */
$redis = $this->pool->getObj(15);
try {
$redis->hDel($this->generateNodeKey($serviceNode), $serviceNode->getNodeId());
Expand All @@ -77,6 +80,8 @@ function serviceNodeHeartBeat(ServiceNode $serviceNode): bool
if (empty($serviceNode->getLastHeartBeat())) {
$serviceNode->setLastHeartBeat(time());
}

/** @var Redis $redis */
$redis = $this->pool->getObj(15);
try {
$redis->hSet($this->generateNodeKey($serviceNode), $serviceNode->getNodeId(), $serviceNode->__toString());
Expand Down

0 comments on commit b04f236

Please sign in to comment.