I have two project on same server (Ubuntu 16.04) with different database, username and also different user_password. But if A project's queue failed, it may insert into B project's failed-job table. Yes, it means sometimes it insert the failed record into the right place. I checked the Laravel config all with default setting. I use the supervisor keep walker. So, anybody has the same problem and a solution for that? I open an issue on github here. https://github.com/laravel/framework/issues/14403
Asked
Active
Viewed 1,889 times
2
-
By multiple projects you mean two or more independent Laravel applications deployed to their own folders? – peterm Jul 21 '16 at 05:37
-
Absolutely yes. Two of them in separated folder like, and created them by use composer.like:composer create-project --prefer-dist laravel/laravel A-Project and composer create-project --prefer-dist laravel/laravel B-Project – Alex Chiang Jul 21 '16 at 06:35
2 Answers
1
By author's reply. I'v solved the problem by this two steps:
1.change the config/cache.php
'prefix' => 'myProjectName', //the default value is laravel.
2.change the config/database.php
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 2, //the default is 0
],
],
You should also pay attention to config/queue.php, if your queue may have more than 60 seconds to finish the job.
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'default',
'expire' => 120, //the default is 60, and would be your like.
],

Alex Chiang
- 1,800
- 2
- 14
- 21
-
2To clarify, Point 1 will not have the suggested effect on queues. The prefix is only added to the cache keys, the prefix is NOT added to the keys used by the queues. It is point 2 (changing the database used for each laravel app) that is resolving the conflict for you. – F3CP May 03 '18 at 01:49
-
Unfortunately, the creator of Redis strongly recommends *against* using that "database" feature and says it was his worst idea: https://stackoverflow.com/a/36498590/470749 – Ryan May 15 '18 at 15:52
0
If you want to resolve the conflict by specifying a prefix for the redis connection rather than by using different databases you can do so with the following config.
For predis (the default client)
'redis' => [
'client' => 'predis',
'cluster' => false,
'options'=>[
'prefix' => 'YOUR_PREFIX_HERE'
],
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
For phpredis client (available since Laravel 5.3):
'redis' => [
'cluster' => false,
'client' => 'phpredis',
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
'prefix' => 'YOUR_PREFIX_HERE:',
],
],

F3CP
- 730
- 5
- 17
-
Can you please elaborate and point to documentation? From what I see in the Laravel source code here, those values that you're passing in as a config array do not get used: https://github.com/illuminate/queue/blob/v5.6.22/Connectors/RedisConnector.php#L43 – Ryan May 15 '18 at 15:49
-
1@Ryan the php redis prefix is documented in the laravel docs https://laravel.com/docs/5.6/redis#phpredis where it states "PhpRedis supports the following additional connection parameters: persistent, prefix, read_timeout and timeout." – F3CP May 21 '18 at 05:29
-
1For predis, the prefix is part of the client options documented here https://github.com/nrk/predis/wiki/Client-Options which, while not documented in the Laravel docs, can be set as part of the Redis config in laravel as indicated in the example above. – F3CP May 21 '18 at 05:33