Connect to Azure Cache for Redis using SSL Port 6380 from Linux VM

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

Scenario:

You are using a Linux VM and you want to connect to Azure Cache for Redis using SSL Port 6380.

 

Action:

You can connect to Azure Cache for Redis using SSL Port with the help of Stunnel and Redis-cli.

The steps are as follows:

Step 1:

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.

 

Step 2:

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

 

Note:

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>

 

Step 3:

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.

 

Step 4:

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.

[redis-cli]

client = yes

accept = 127.0.0.1:6380

connect = yourcachename.redis.cache.windows.net:6380

Save the file.

 

Step 5:

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

 

Step 6:

If you check the services listening for connections on your Redis, you should see stunnel listening on port 6380 as below:

sudo netstat -plunt

 

Step 7:

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!

 

REMEMBER: these articles are REPUBLISHED. Your best bet to get a reply is to follow the link at the top of the post to the ORIGINAL post! BUT you're more than welcome to start discussions here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.