2

This project was set up by another team and I'm unable to get passed this one error. Using PHP 7.2 and Laravel 6.2. My docker-compose.yml:

redis:
    image: redis
    command: ["redis-server", "--appendonly", "yes","--requirepass","Redis.123"]
    volumes:
      - redis-data:/data
    container_name: redis-master
    ports:
      - "6379:6379"

and database.php:

'redis' => [

        'client' => env('REDIS_CLIENT', 'phpredis'),

        'options' => [
            'cluster' => env('REDIS_CLUSTER', 'redis'),
            'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
        ],

        'default' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_DB', 0),
        ],

        'cache' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => env('REDIS_CACHE_DB', 1),
        ],

    ]

The container is up and running and "Ready to accept connections". This error is in my stack trace if I attempt to hit the base url or any endpoints. I have aliased redis in app.php: 'RedisManager' => Illuminate\Support\Facades\Redis::class, as others have recommended. Can anyone see anything obvious that is missing or could cause this? Predis is installed in the composer.json: "predis/predis": "^1.1",, but not set in the config. If I changed phpredis to predis I get the error development.ERROR:SELECTfailed: NOAUTH Authentication required. [tcp://127.0.0.1:6379].

Ersoy
  • 8,816
  • 6
  • 34
  • 48
Matt Larsuma
  • 1,456
  • 4
  • 20
  • 52

2 Answers2

2

The error you get when you set to phpredis, it is most likely related to phpredis extension. You need to install this extension if you want to use phpredis client.

The error you get when you set it to predis is totally different. It is authentication error because you didn't set password. In your .env file, append this

REDIS_PASSWORD=Redis.123

Then artisan config:clear, it could do the work.

Ersoy
  • 8,816
  • 6
  • 34
  • 48
  • I'm using envkey for my .env and the REDIS_PASSWORD in there is null, so I'm guessing phpredis was intended. I checked and I have redis in my php.ini correctly: `php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"` returns OK and php -i | grep Redis looks good as well: `Redis Support => enabled Redis Version => 5.2.2 Redis Sentinel Version => 0.1`. I also have `extension="redis.so"` at the top of my php7.2.ini and have restarted php7.2 with `brew services restart php@7.2`. – Matt Larsuma Jun 16 '20 at 21:07
  • what happens if you set `phpredis` as `REDIS_CLIENT` with the set password as i offered in the answer ? Do you get any error or it works ? @MattLarson – Ersoy Jun 16 '20 at 21:10
  • 1
    I ended up doing a full reboot and phpredis was working, but ended up needing the REDIS_PASSWORD anyway, so added that to envkey. Thanks! – Matt Larsuma Jun 16 '20 at 21:28
0

In .end file, please put REDIS_HOST=redis-master which is your redis container name.

LoveCoding
  • 1,121
  • 2
  • 12
  • 33