改名
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace HttpServer;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Snowflake\Abstracts\Component;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
|
||||
/**
|
||||
* Class Emit
|
||||
* @package HttpServer
|
||||
*/
|
||||
class Emit extends Component
|
||||
{
|
||||
|
||||
private array $_array = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $message
|
||||
* @throws Exception
|
||||
*/
|
||||
public function emit(string $name, string $message)
|
||||
{
|
||||
$redis = Snowflake::app()->getRedis();
|
||||
if (!$redis->exists($name) || $redis->sCard($name) < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$socket = Snowflake::app()->getSwoole();
|
||||
foreach ($redis->sMembers($name) as $value) {
|
||||
$socket->push($value, $message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param int $value
|
||||
* @throws Exception
|
||||
*/
|
||||
public function register(string $name, int $value)
|
||||
{
|
||||
redis()->sAdd($name, $value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param int|null $value
|
||||
* @throws Exception
|
||||
*/
|
||||
public function clear(string $name, ?int $value = null)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
redis()->sRem($name, $value);
|
||||
} else {
|
||||
redis()->del($name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use Database\DatabasesProviders;
|
||||
use HttpServer\Client\Client;
|
||||
use HttpServer\Client\Curl;
|
||||
use HttpServer\Client\Http2;
|
||||
use HttpServer\Emit;
|
||||
use HttpServer\Http\Request;
|
||||
use HttpServer\Http\Response;
|
||||
use HttpServer\HttpFilter;
|
||||
@@ -52,6 +53,7 @@ use Rpc\Producer as RPCProducer;
|
||||
* @property RPCProducer $rpc
|
||||
* @property Channel $channel
|
||||
* @property Shutdown $shutdown
|
||||
* @property Emit $emit
|
||||
*/
|
||||
trait TraitApplication
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user