我正在使用 windows os.Installed redis 并启动。我event(new PrivateMessageEvent($data));在控制器中触发一个事件
事件
class PrivateMessageEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $data;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('private-channel');
}
public function broadcastWith()
{
return [
'data' => $this->data
];
}
public function handle() {
}
我已经排好队了。
RedisBroadcaster 被调用。但是当命令执行时它返回零。我检查了日志。
namespace Illuminate\Redis\Connections;
use Closure;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Redis\Events\CommandExecuted;
use Illuminate\Redis\Limiters\ConcurrencyLimiterBuilder;
use Illuminate\Redis\Limiters\DurationLimiterBuilder;
use Illuminate\Support\Traits\Macroable;
abstract class Connection
{
public function command($method, array $parameters = [])
{
$start = microtime(true);
$result = $this->client->{$method}(...$parameters);
$time = round((microtime(true) - $start) * 1000, 2);
if (isset($this->events)) {
$this->event(new CommandExecuted($method, $parameters, $time, $this));
}
return $result;
}
1)$result = $this->client->{$method}(...$parameters);命令执行成功时应该返回什么行
2) ($this->client)Redis 类路径/命名空间在哪里
环境噪声
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
数据库
'redis' => [
'client' => env('REDIS_CLIENT', 'phpredis'),
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'database' => 0,
'port' => env('REDIS_PORT', '6379'),
]
]
服务.js
http.listen(8005, function () {
console.log('Listening to port 8005');
});
redis.subscribe('private-channel', function() {
console.log('subscribed to private channel');
});
redis.on('message', function(channel, message) {
message = JSON.parse(message);
console.log(message);
if (channel == 'private-channel') {
let data = message.data.data;
let receiver_id = data.receiver_id;
let event = message.event;
io.to(`${users[receiver_id]}`).emit(channel + ':' + message.event, data);
}
});
我是否缺少任何 redis 配置。