Skip to content

Access Redis CLI via Port Forward#

This documentation will help to connect to managed Redis via redis-cli using port forward.

CLI Setup#

The first step is to setup redis-cli on your local machine. For this, go through following steps. If you already have CLI setup, you can skip this section.

  • Run following command in terminal
sudo apt install redis-tools
  • Run following command to verify CLI installation.
redis-cli --version

Create Port Forwarding to Redis Service#

Before running redis-cli command we need to port forward to Redis service running in cluster. To achieve this, perform following steps:

  • In OpenShift console, click on your username on top right corner and click Copy login command as shown below: OpenShift Console
  • Click on Display Token and then copy oc login command.
  • Run this command inside your terminal. Now you have access to interact with your cluster using terminal.
  • Run following command to locate service to which we need to create port forward.
oc get svc -n <redis-namespace>  

Here <redis-namespace> is the name of namespace where Redis is deployed (In current case its value is bitnami-redis). This name might be different for you. You can ask about this to cluster admin. - You'll get an output similar to one shown below: Redis Services - Run the following command to create port forward.

oc port-forward svc/<service-name> <port> -n <redis-namespace>
- `<service-name>` is the name of service that has `CLUSTER-IP` assigned. In current case its value is `bitnami-redis`.
- `<port>` is the port number for this service to which we need to create port forward. For sentinel mode we need to port forward to port `26379` otherwise to `6379`.
  • This should result in following output: Redis Port Forward
  • At this moment, you need to open a second terminal (while keeping this running) and run following command:
redis-cli -h 127.0.0.1 -p <port> -a <password>
- Here `<password>` should be replaced by password used to connect to Redis. This password can easily be retrieved from Vault.
  • At this moment, you should have access to redis-cli. As shown below by doing a simple operation on Redis. Redis CLI