【发布时间】:2015-09-10 18:25:28
【问题描述】:
我有以下事件:
<?php
namespace SixtyFiveContrib\Events;
use Auth;
use SixtyFiveContrib\Events\Event;
use SixtyFiveContrib\Models\Notification;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
/**
* NotificationEvent
*
*/
class NotificationEvent extends Event implements ShouldBroadcast
{
use SerializesModels;
public $notification;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Notification $notification)
{
$this->notification = $notification;
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return ['feed', 'updates'];
}
public function broadcastWith()
{
return ['notification' => $this->notification];
}
}
我在 broadcasting.php 中使用 Redis 驱动
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
然后我有来自官方文档的节点应用程序,它运行良好并连接到客户端:
var app = require('http').createServer(handler);
var io = require('socket.io')(app);
var Redis = require('ioredis');
var redis = new Redis();
app.listen(3000, function() {
console.log('Server is running!');
});
function handler(req, res) {
res.writeHead(200);
res.end('Ayup.');
}
io.on('connection', function(socket) {
//
});
redis.psubscribe('*', function(err, count) {
console.log(err);
});
redis.on('pmessage', function(subscribed, channel, message) {
message = JSON.parse(message);
console.log(subscribed);
console.log(channel);
console.log(message);
io.emit(channel + ':' + message.event, message.data);
});
节点应用程序没有从 Redis 接收任何内容?如果我手动进入 redis-cli 并运行 ``` PUBLISH feed '{event: "SixtyFiveContrib\Events\NotificationEvent"}' 那么节点应用程序确实会收到该消息。
提前干杯!
【问题讨论】:
-
你有没有机会同时使用 redis 会话和缓存驱动程序?
-
@DavidBarker 我确实是!这会导致某种形式的冲突吗?
-
在 5.1 发布之前我第一次使用它时,它确实发生了。我必须将缓存驱动程序设置为 redis 以外的任何内容才能使其正常工作。
-
你确定吗,你已经在 .env 文件中配置了驱动。 broadcasting.php 有那一行 'default' => env('BROADCAST_DRIVER', 'pusher'),
标签: laravel redis socket.io laravel-5