我得到了一个Redis集群服务器,我按照本教程创建。
这就是我的database/config.php设置的样子(详见here):
'redis' => [
'client' => 'predis',
'cluster' => true,
'options' => [
'cluster' => 'redis',
'parameters' => [
'host' => env('REDIS_DEFAULT_HOST', '127.0.01'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_DEFAULT_PORT', 6379),
'database' => 0,
],
],
'clusters' => [
'default' => [
'host' => env('REDIS_DEFAULT_HOST', '127.0.01'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_DEFAULT_PORT', 6379),
'database' => 0,
],
'jobs' => [
'host' => env('REDIS_JOBS_HOST', '127.0.01'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_JOBS_PORT', 6379),
'database' => 0,
],
'content' => [
'host' => env('REDIS_CONTENT_HOST', '127.0.01'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_CONTENT_PORT', 6379),
'database' => 0,
],
'options' => [
'cluster' => 'redis'
],
]
]
我的config/broadcasting.php看起来像什么:
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Broadcaster
|--------------------------------------------------------------------------
|
| This option controls the default broadcaster that will be used by the
| framework when an event needs to be broadcast. You may set this to
| any of the connections defined in the "connections" array below.
|
*/
'default' => env('BROADCAST_DRIVER', 'redis'),
/*
|--------------------------------------------------------------------------
| Broadcast Connections
|--------------------------------------------------------------------------
|
| Here you may define all of the broadcast connections that will be used
| to broadcast events to other systems or over websockets. Samples of
| each available type of connection are provided inside this array.
|
*/
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_KEY'),
'secret' => env('PUSHER_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
],
];
当我想在redis中发布一个事件时,在代码中到达这一部分:
// Dispatch an event indicates order status has been changed.
event(new OrderStatusChanged($order->id, OrderActionsConstants::INCOMPLETE_CART));
我得到这个错误:
Cannot use 'PUBLISH' with redis-cluster.
使用此堆栈跟踪
[2019-06-10 17:05:06] local.ERROR:
0 /Users/Shared/dev/php/toters-api/vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(550): Predis\Connection\Aggregate\RedisCluster->getConnection(Object(Predis\Command\PubSubPublish))
1 /Users/Shared/dev/php/toters-api/vendor/predis/predis/src/Connection/Aggregate/RedisCluster.php(593): Predis\Connection\Aggregate\RedisCluster->retryCommandOnFailure(Object(Predis\Command\PubSubPublish), 'executeCommand')
2 /Users/Shared$dev/php/toters-api/vendor/predis/predis/src/Client.php(331): Predis\Connection\Aggregate\RedisCluster->executeCommand(Object(Predis\Command\PubSubPublish))
3 /Users/Shared/dev/php/toters-api/vendor/predis/predis/src/Client.php(314): Pre$is\Client->executeCommand(Object(Predis\Command\PubSubPublish))
4 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(72): Predis\Client->__call('publish', Array)
5 /Users/Shared/de$/php/toters-api/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(84): Illuminate\Redis\Connections\Connection->command('publish', Array)
6 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/$roadcasting/Broadcasters/RedisBroadcaster.php(99): Illuminate\Redis\Connections\Connection->__call('publish', Array)
7 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastEvent.php(48): Illumin$te\Broadcasting\Broadcasters\RedisBroadcaster->broadcast(Array, 'order.status', '{"event":"order...')
8 [internal function]: Illuminate\Broadcasting\BroadcastEvent->handle(Object(Illuminate\Broadcasting\Broadcasters\RedisBroadcaster))
$ /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
10 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Container/BoundMetho$.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
11 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Ob$ect(Illuminate\Foundation\Application), Array, Object(Closure))
12 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Container/Container.php(539): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundatio$\Application), Array, Array, NULL)
13 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): Illuminate\Container\Container->call(Array)
14 /Users/Shared/dev/php/toters-api/vendor/laravel/frame$ork/src/Illuminate/Pipeline/Pipeline.php(114): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
15 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Pipeline/Pipe$ine.php(102): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Broadcasting\BroadcastEvent))
16 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): Illuminate\Pip$line\Pipeline->then(Object(Closure))
17 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(42): Illuminate\Bus\Dispatcher->dispatchNow(Object(Illuminate\Broadcasting\BroadcastEvent), fal$e)
18 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(69): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\SyncJob), Array)
19 /Users/Shared/dev/php/toters-api/vendor/la$avel/framework/src/Illuminate/Queue/SyncQueue.php(42): Illuminate\Queue\Jobs\Job->fire()
20 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Queue/Queue.php(42): Illuminate\Queue\SyncQueue->push(Object(Illuminate$Broadcasting\BroadcastEvent), '', NULL)
21 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Broadcasting/BroadcastManager.php(128): Illuminate\Queue\Queue->pushOn(NULL, Object(Illuminate\Broadcasting\BroadcastEve$t))
22 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(270): Illuminate\Broadcasting\BroadcastManager->queue(Object(App\Events\OrderStatusChanged))
23 /Users/Shared/dev/php/toters-api/vend$r/laravel/framework/src/Illuminate/Events/Dispatcher.php(193): Illuminate\Events\Dispatcher->broadcastEvent(Object(App\Events\OrderStatusChanged))
24 /Users/Shared/dev/php/toters-api/vendor/laravel/framework/src/Illuminate/Foundation/he$pers.php(446): Illuminate\Events\Dispatcher->dispatch('App\\Events\\Orde...')
25 /Users/Shared/dev/php/toters-api/app/Repositories/Orders/AppOrdersRepo.php(107): event(Object(App\Events\OrderStatusChanged))
我该怎么解决这个问题?
1条答案
按热度按时间bxgwgixi1#
您在配置文件中有错误
定义一个群集时,例如default i必须包含主机定义阵列
在您的特定示例中,配置文件将是:
]