You are using a Linux VM and you want to connect to Azure Cache for Redis using SSL Port 6380.
You can connect to Azure Cache for Redis using SSL Port with the help of Stunnel and Redis-cli.
The steps are as follows:
Install the Redis-cli tool in your Linux machine. The command is as below:
sudo apt-get update
sudo apt-get install redis-tools
Note: redis-tools package has redis-cli tool as well among other tools.
Since the redis-cli doesn’t support SSL port (6380), we can make use of stunnel to connect to Azure Cache for Redis using SSL port. We have version 4 of the utility, called stunnel4 which can be installed using the below command:
sudo apt-get install stunnel4
If you want to run the Redis using non SSL port 6379, in that case you do not need stunnel and you can directly access using the below command provided non-ssl port is open in Azure Cache for Redis:
redis-cli -p 6379 -a <Your Access Key for Azure Cache for Redis> -h < yourcachename.redis.cache.windows.net>
To configure the service to start at booting, you must modify the /etc/default/stunnel4 file using the below command:
sudo nano /etc/default/stunnel4
This opens a file where you have a variable ‘ENABLED’ which must be set to 1 to enable the service to start as shown below:
You can save the changes with CTL+X and then pressing ENTER.
We need to configure the Azure Cache for Redis for redis-cli which must be mentioned in Redis configuration file of stunnel.
Execute the below command:
sudo nano /etc/stunnel/redis.conf
This creates a new file where add the following entry and insert the actual name of your Azure Cache for Redis in place of yourcachename.
client = yes
accept = 127.0.0.1:6380
connect = yourcachename.redis.cache.windows.net:6380
Save the file.
Now, we have configured the stunnel and hence need to restart the service which can be done with the help of below command:
sudo systemctl restart stunnel4.service
If you check the services listening for connections on your Redis, you should see stunnel listening on port 6380 as below:
sudo netstat -plunt
Now you can connect to Azure Cache for Redis using SSL port with the help of Redis-cli. Below is the command:
redis-cli -p 6380 -a <Your Access Key for Azure Cache for Redis>
You can see that Redis gets connected successfully and you will be able to perform operations on Azure Cache for Redis:
Hope this helps!