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]);
}
}