php – Gitlab CI configuration with Laravel Docker Redis wrong host or port-ThrowExceptions

Exception or error:

I’m working on a Gitlab CI configuration in the .gitlab-ci.yml file for a Laravel project which uses redis as Cache Driver. Within this configuration file I use an image which has all the linux packages, php extension which are used on our production environment. This includes the redis extension installed by pecl so phpredis can be used within Laravel.

After spending a fair amount of time into learning the process of continuous integration and the configuration of the gitlab ci file I encountered the following error on deploy of the image:

In PhpRedisConnector.php line 126:

   Redis::connect() expects parameter 2 to be int, string given  

parameter should be only the port as an int but somehow turned into tcp://

As documented the host in your .env should be redis so I had. Dumping the config during the deploy resulted in port being some tcp:// connection string and host being empty. There is no way this is changed within our application or any extension we use.

I use the as a service in the .gitlab-ci.yml.

  - name: redis:4
How to solve:

Solution found here:

This variable isn’t documented anywhere but somehow it solves the problem.
Add the following to your .gitlab-ci.yml file:

  REDIS_PORT: 6379

If anyone finds documentation about this variable and maybe more options, let me know!

Leave a Reply

Your email address will not be published. Required fields are marked *