"Failed to parse address" on Redis connection - Laravel + Predis + Laradock

Published 1 week ago by getupkid

Hi everyone, I'm trying to setup Redis with a fresh laravel application. I set it as the driver for both caching and sessions.

However, I am getting this exception thrown:

 Predis \ Connection \ ConnectionException
 Failed to parse address "redis:tcp://172.17.0.13:6379" [tcp://redis:tcp://172.17.0.13:6379]

It sounds like something to do with the way the address is written but can't figure it out.

Here are some relevant details:

config/database.php

      'redis' => [

         'client' => 'predis',

         'cluster' => false,

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

     ]

config/session.php

      'driver' => env('SESSION_DRIVER', 'redis'),
      'connection' => 'default',

config/cache.php

      'default' => env('CACHE_DRIVER', 'redis'),

 'stores' => [

         'redis' => [
             'driver' => 'redis',
             'connection' => 'default',
         ],

     ],

docker-compose.yml

      redis:
            build: ./laradock/redis
            volumes:
              - ./storage/data/redis:/data
            expose:
             - "6379"
            network_mode: bridge
Best Answer (As Selected By getupkid)
getupkid

@Talinon I figured it out... Docker was creating an environment variable REDIS_PORT that was being set to "tcp://172.17.0.5:6379". Not sure why, but anyways...

Changing my config/database.php to:

 'default' => [
             'host' => env('REDIS_HOST', 'redis'),
             'password' => env('REDIS_PASSWORD', null),
             'port' => 6379,
             'database' => 0,
         ],

solved the problem!

You definitely got me on the right track so thank you =)

Talinon
Talinon
1 week ago (39,120 XP)

Do you have REDIS_HOST defined in your .env file?

I'd double check your setting there, as it looks like you might have more than just a host/ip defined?

getupkid

@Talinon nope I don't have any Redis stuff in the .env - it's all done through the config files.

Talinon
Talinon
1 week ago (39,120 XP)

What does getenv('REDIS_HOST') return?

getupkid

@Talinon it returns blank

Talinon
Talinon
1 week ago (39,120 XP)

If it is not defined, it should return false, not blank. It's not immediately obvious to me what the problem might be. Hopefully someone else might have an idea.

For fun, have you tried just providing an IP in the config/database.php to see if it changes the parse error?

 'host' => '172.17.0.13'
getupkid

@Talinon I did try that, it gives the same error just with the address in it instead.

I believe it has something to do with the docker networking setup I'm using. I just tried it with the default laradock config and it was working fine.

It's just odd cause I have no issues with MySQL or anything else using the same setup. I'll see what I can figure out.

Thanks for your help anyway!

getupkid

@Talinon I figured it out... Docker was creating an environment variable REDIS_PORT that was being set to "tcp://172.17.0.5:6379". Not sure why, but anyways...

Changing my config/database.php to:

 'default' => [
             'host' => env('REDIS_HOST', 'redis'),
             'password' => env('REDIS_PASSWORD', null),
             'port' => 6379,
             'database' => 0,
         ],

solved the problem!

You definitely got me on the right track so thank you =)

Please sign in or create an account to participate in this conversation.