diff --git a/HttpServer/Emit.php b/HttpServer/Emit.php new file mode 100644 index 00000000..7f782e45 --- /dev/null +++ b/HttpServer/Emit.php @@ -0,0 +1,67 @@ +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); + } + } + + +} diff --git a/System/Abstracts/TraitApplication.php b/System/Abstracts/TraitApplication.php index c9ec165c..c1ea821f 100644 --- a/System/Abstracts/TraitApplication.php +++ b/System/Abstracts/TraitApplication.php @@ -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 {