Published 10 months 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:
'redis' => [ 'client' => 'predis', 'cluster' => false, 'default' => [ 'host' => env('REDIS_HOST', 'redis'), 'password' => env('REDIS_PASSWORD', null), 'port' => env('REDIS_PORT', 6379), 'database' => 0, ], ]
'driver' => env('SESSION_DRIVER', 'redis'), 'connection' => 'default',
'default' => env('CACHE_DRIVER', 'redis'), 'stores' => [ 'redis' => [ 'driver' => 'redis', 'connection' => 'default', ], ],
redis: build: ./laradock/redis volumes: - ./storage/data/redis:/data expose: - "6379" network_mode: bridge
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'
@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!
@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 =)