Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit e454f53

Browse files
committed
Initial implementation of Redis as a pub/sub backend, WIP
TODO: - Presence channels need the user lists stored in Redis (tricky, requires a lot of changes and async code in HTTP controllers) - Channels in Redis should be scoped by the app ID
1 parent c203d24 commit e454f53

File tree

10 files changed

+448
-151
lines changed

10 files changed

+448
-151
lines changed

PubSub/PubSubInterface.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

PubSub/Redis/RedisClient.php

Lines changed: 0 additions & 118 deletions
This file was deleted.

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
"php": "^7.1",
2626
"ext-json": "*",
2727
"cboden/ratchet": "^0.4.1",
28-
"clue/block-react": "^1.3",
2928
"clue/buzz-react": "^2.5",
30-
"clue/redis-react": "^2.2",
29+
"clue/redis-react": "^2.3",
3130
"facade/ignition-contracts": "^1.0",
3231
"guzzlehttp/psr7": "^1.5",
3332
"illuminate/broadcasting": "5.7.* || 5.8.* || ^6.0",

src/Console/StartWebSocketServer.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
use React\Dns\Resolver\ResolverInterface;
1010
use React\EventLoop\Factory as LoopFactory;
1111
use React\Dns\Resolver\Factory as DnsFactory;
12-
use BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
13-
use BeyondCode\LaravelWebSockets\PubSub\PubSubInterface;
12+
use BeyondCode\LaravelWebSockets\PubSub\ReplicationInterface;
1413
use BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
1514
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
1615
use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;
@@ -146,13 +145,11 @@ protected function configurePubSubReplication()
146145
}
147146

148147
if (config('websockets.replication.driver') === 'redis') {
149-
$connection = (new RedisClient())->subscribe($this->loop);
148+
app()->singleton(ReplicationInterface::class, function () {
149+
return (new RedisClient())->boot($this->loop);
150+
});
150151
}
151152

152-
app()->singleton(PubSubInterface::class, function () use ($connection) {
153-
return $connection;
154-
});
155-
156153
return $this;
157154
}
158155

src/HttpApi/Controllers/Controller.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function onOpen(ConnectionInterface $connection, RequestInterface $reques
4646

4747
$this->requestBuffer = (string) $request->getBody();
4848

49-
if (! $this->checkContentLength()) {
49+
if (! $this->verifyContentLength()) {
5050
return;
5151
}
5252

@@ -64,16 +64,16 @@ public function onMessage(ConnectionInterface $from, $msg)
6464
{
6565
$this->requestBuffer .= $msg;
6666

67-
if (! $this->checkContentLength()) {
67+
if (! $this->verifyContentLength()) {
6868
return;
6969
}
7070

7171
$this->handleRequest($from);
7272
}
7373

74-
protected function checkContentLength()
74+
protected function verifyContentLength()
7575
{
76-
return strlen($this->requestBuffer) !== $this->contentLength;
76+
return strlen($this->requestBuffer) === $this->contentLength;
7777
}
7878

7979
protected function handleRequest(ConnectionInterface $connection)

0 commit comments

Comments
 (0)