I am having problems connecting to Redis from outside its environment

I have one project and two environments within this project.

Redis is hosted on one of the these environments (ENV A) while my app is hosted in the other environment (ENV B).

I will need my app in ENV B to connect to redis in ENV A.

Just for context ENV A and ENV B live in the same project.

For context, Redis is hosted privately as a container in ENV A. It exposese the following ENV variables

QOVERY_REDIS_Zxxxxx_HOST_INTERNAL=zxxxxx-redis
QOVERY_REDIS_Zxxxxx_DEFAULT_DATABASE_NAME=0
QOVERY_REDIS_Zxxxxx_LOGIN=
QOVERY_REDIS_Zxxxxx_PORT=6379

For clarity QOVERY_REDIS_Zxxxxx_LOGIN variable is blank

For my app to connect to Redis, I created the following environment variable within my APP’s environment:

REDIS_HOST=zxxxxx-redis.z${PROJECT_id}-z${ENV_A_id}
REDIS_DB=0

Even with this configuration, my app can’t connect to Redis

error: Error connecting to Redis

Do I need a username to login to Redis ?

Where did you create this environment variable? Inside your Dockerfile? Did you declare ARG PROJECT_ID and ARG ENV_A_ID inside your Dockerfile?

If there is no login, then it means that you don’t need a login.


:warning: Side note: we discussed yesterday this use case of connecting one app from environment A to environment B, but I want to point to other readers that it is an anti-pattern with Qovery since you risk having network issues since an environment A can be entirely out of the network of environment B.

The environment variable was created in Qovery using terraform (So i can see it on the UI)

Yes you mentoned it is an anti pattern but let me also mention that nsloookup resolves the service name and also i can telnet to the redis port too

Yes absolutely :ok_hand:

i can perform nsloookup and telnet but still my application can’t connect to Redis

Here is an example from my application on Qovery

# redis-cli -u redis://:X109iJxr44up8Yr49GNfU-RDD24hzafY@z1b97ba3e-redis:6379/0
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
z1b97ba3e-redis:6379>

and with the separated args

# redis-cli -h z1b97ba3e-redis --pass X109iJxr44up8Yr49GNfU-RDD24hzafY -p 6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
z1b97ba3e-redis:6379>

with the separated args AND internal domain (zPROJECT-zENV)

# redis-cli -h z1b97ba3e-redis.z427be40b-z8d3c3431 --pass X109iJxr44up8Yr49GNfU-RDD24hzafY -p 6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
z1b97ba3e-redis.z427be40b-z8d3c3431:6379> PING
PONG

Can you validate on your side?

But I don’t have a password.

How do I get the password ?

Since you need to inject it between 2 different environments, you can get your database password from environment A like this :point_down:

yes this has worked - thanks

1 Like