We have a new Symfony setup with Redis as cache mechanism. We want to connect to a specific host, not the default localhost. On production, the ./bin/console debug:dotenv gives the correct REDIS_HOST. This is configured in our .env and .env.local.php.
The error we get is:
Connection refused: tcp:127.0.0.1/6379
This is our config:
services.yml
services:
Redis:
# you can also use RedisArray, RedisCluster or PredisClient classes
class: PredisClient
calls:
- connect:
- '%env(REDIS_HOST)%'
- '%env(int:REDIS_PORT)%'
SymfonyComponentHttpFoundationSessionStorageHandlerRedisSessionHandler:
arguments:
- '@Redis'
- prefix: sp_ss_
- ttl: 1800
cache.yml
framework:
cache:
app: cache.adapter.redis
default_redis_provider: 'Redis'
pools:
site.cache:
adapter: cache.app
And our .env file:
APP_ENV=prod
APP_SECRET=****
MESSENGER_TRANSPORT_DSN=redis://redis.local:6379/messages
REDIS_HOST=redis.local
REDIS_PORT=6379
REDIS_URL=redis://redis.local:6379
2
Answers
There might be hidden other .env files. May you check out the files list with the following code at the root of your projects? Are there other env files such as .env.prod, .env.local?
The Symfony’s documentation suggest to use "calls -> connect", but it’s used only when you was defined the class as ‘Redis’. When you use ‘PredisClient’, you need to use the settings bellow:
"config/services.yaml"
I’m also using the ‘PredisClient’ and after to change to ‘arguments’ the connection was worked here.
For more parameters references, please check this link (List of connection parameters).