Question: I have created a redis 3.2 application from the default image catalog.

I'm trying to connect a python app that runs inside the same project with the redis db.

This is what the Python application uses to connect to redis:

```py
REDIS_HOST = 'localhost'
REDIS_PORT = 6379
REDIS_PASSWORD = os.environ.get('REDIS_PASSWORD') or 'test'

redis = aioredis.create_redis_pool(
    (REDIS_HOST, int(REDIS_PORT)),
    password=REDIS_PASSWORD,
    minsize=5,
    maxsize=10,
    loop=loop,
)

```

The deployment fails with an `ConnectionRefusedError: [Errno 111] Connection refused`.

My guess is that I need to use another value for REDIS\_HOST, but I couldn't figure what to use.

Does anyone know how to fix this?

Answer: 
After you deployed from the image catalog a number of objects will have been created for you. One of those objects is a service, which is used to load balance requests to the Pods it fronts. Service names for a project can be retrieved using the client tools via `oc get svc`.

This service name should be used to connect to your redis instance. If you deploy redis before your Python application, some environment variables should already be populated which can be used, for example `REDIS_SERVICE_HOST` and `REDIS_SERVICE_PORT`.

So from your application you can connect via the service ip or service name, where service name is `redis` then `redis.StrictRedis(host='redis', port=6379, password='secret')`

The redis password may have been generated for you. In that case it is retrievable from the redis secret which could also be mounted from your python app
Databases in general do not use standard HTTP, but custom TCP protocols. This is why in Openshift we need to connect directly to the service using Openshift's Service hostname or IP address (caution: only Service hostname is predictable), instead of the usual Route, and this applies also to Redis. Bypassing the Routes in Openshift is like bypassing a reverse proxy such as nginx and directly connecting to the db backend.

There is need to use env variables, because service hostnames are auto-generated by Openshift using this predictable pattern:
`container_name.project_name.svc` , e.g:
`redis.db.svc`

* More info
"When a web application is made visible outside of the OpenShift cluster a route is created. This enables a user to use a URL to access the web application from a web browser. A route is usually used for web applications which use the HTTP protocol. A route cannot be used to expose a database, as they would typically use their own distinct protocol, and routes would not be able to work with the database protocol."
[<https://blog.openshift.com/openshift-connecting-database-using-port-forwarding/> ]