Bravo3\Orm\Drivers\Redis\RedisDriver::listenToPubSub PHP Method

listenToPubSub() public method

Add a callback to a particular subscription channel.
public listenToPubSub ( callable $callback ) : void
$callback callable
return void
    public function listenToPubSub(callable $callback)
    {
        while (1) {
            $command = RawCommand::create('PSUBSCRIBE', sprintf('%s-%s', $this->pubsub_channel_prefix, '*'));
            $this->client->executeCommand($command);
            if ($this->client->getConnection() instanceof MasterSlaveReplication) {
                $payload = $this->client->getConnection()->getConnection($command)->read();
            } else {
                $payload = $this->client->getConnection()->read();
            }
            $channel = ltrim($payload[2], sprintf('%s%s', $this->pubsub_channel_prefix, '-'));
            $message = base64_decode($payload[3]);
            call_user_func($callback, ['channel' => $channel, 'message' => $message]);
        }
    }