Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 19, 2024
1 parent 8075162 commit 0ea48b2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 61 deletions.
49 changes: 0 additions & 49 deletions src/Concerns/InteractsWithAsyncRedis.php

This file was deleted.

10 changes: 5 additions & 5 deletions src/Servers/Reverb/Console/Commands/StartServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Laravel\Reverb\Application;
use Laravel\Reverb\Concerns\InteractsWithAsyncRedis;
use Laravel\Reverb\Contracts\ApplicationProvider;
use Laravel\Reverb\Contracts\Logger;
use Laravel\Reverb\Jobs\PingInactiveConnections;
Expand All @@ -22,8 +21,6 @@

class StartServer extends Command implements SignalableCommandInterface
{
use InteractsWithAsyncRedis;

/**
* The name and signature of the console command.
*
Expand Down Expand Up @@ -58,8 +55,11 @@ public function handle(): void

$server = ServerFactory::make($host, $port, loop: $loop);

$this->laravel->make(PubSubProvider::class)->connect($loop);
$this->subscribeToRedis($loop);
if ($this->laravel->make(ServerServiceProviderManager::class)->subscribesToEvents()) {
$this->laravel->make(PubSubProvider::class)->connect($loop);
$this->laravel->make(PubSubProvider::class)->subscribe();
}

$this->scheduleCleanup($loop);
$this->checkForRestartSignal($server, $loop, $host, $port);

Expand Down
29 changes: 26 additions & 3 deletions src/Servers/Reverb/Publishing/RedisPubSubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

namespace Laravel\Reverb\Servers\Reverb\Publishing;

use Laravel\Reverb\Concerns\InteractsWithAsyncRedis;
use Illuminate\Support\Facades\Config;
use Laravel\Reverb\Protocols\Pusher\EventDispatcher;
use Laravel\Reverb\Servers\Reverb\Contracts\PubSubProvider;
use React\EventLoop\LoopInterface;
use RuntimeException;

class RedisPubSubProvider implements PubSubProvider
{
use InteractsWithAsyncRedis;

protected $publishingClient;

protected $subscribingClient;
Expand Down Expand Up @@ -59,6 +57,31 @@ public function publish(array $payload): void
$this->publishingClient->publish($this->channel, json_encode($payload));
}

/**
* Get the connection URL for Redis.
*/
protected function redisUrl(): string
{
$config = Config::get('database.redis.default');

$host = $config['host'];
$port = $config['port'] ?: 6379;

$query = [];

if ($config['password']) {
$query['password'] = $config['password'];
}

if ($config['database']) {
$query['db'] = $config['database'];
}

$query = http_build_query($query);

return "redis://{$host}:{$port}".($query ? "?{$query}" : '');
}

/**
* Ensure that a connection to Redis has been established.
*/
Expand Down
5 changes: 1 addition & 4 deletions tests/ReverbTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Laravel\Reverb\Tests;

use Illuminate\Support\Str;
use Laravel\Reverb\Concerns\InteractsWithAsyncRedis;
use Laravel\Reverb\Servers\Reverb\Contracts\PubSubProvider;
use Laravel\Reverb\Servers\Reverb\Factory;
use Laravel\Reverb\ServerServiceProviderManager;
Expand All @@ -18,8 +17,6 @@

class ReverbTestCase extends TestCase
{
use InteractsWithAsyncRedis;

protected $server;

protected $loop;
Expand Down Expand Up @@ -79,7 +76,7 @@ public function usingRedis(): void
app(ServerServiceProviderManager::class)->withPublishing();

app(PubSubProvider::class)->connect($this->loop);
$this->subscribeToRedis($this->loop);
app(PubSubProvider::class)->subscribe();
}

/**
Expand Down

0 comments on commit 0ea48b2

Please sign in to comment.