user189198
user189198

Reputation:

Redis CLI disconnects immediately when setting a key in Azure Redis Cache

I provisioned an Azure Redis Cache, under the Basic 250MB tier, with TLS version set to Default. I used the Redis CLI from Windows 10 version 2004. I also attempted to use Redis CLI from a Multipass Ubuntu Linux VM, and got the same result.

I run the following command to get an interactive Redis CLI prompt, which is painfully slow at around 10 seconds:

redis-cli -h mytestcache658.redis.cache.windows.net -p 6380 -a 'REDACTEDREDACTED'

Then I run a simple Redis command from the interactive CLI:

mytestcache658.redis.cache.windows.net:6380> SET FirstName Trevor

As soon as I run this command, I immediately am disconnected from the Azure Redis Cache.

On Windows 10, Redis CLI version 3.2.100, I receive this error:

Error: An existing connection was forcibly closed by the remote host.

On Ubuntu Linux with Redis CLI version 5.0.7, I receive this error:

Error: Connection reset by peer

Question: How exactly do I use Azure Redis Cache? It doesn't appear to be working at all.

Upvotes: 1

Views: 5352

Answers (1)

user189198
user189198

Reputation:

Apparently the version of Redis that's running in Azure is an older version (4.0). Redis doesn't support TLS until version 6.0, as an optional feature, according to their documentation. Of course, nothing in the Azure Portal actually tells you this.

Eventually, after conferring with several colleagues, I came across a broken link to a 6 year-old blog post on an unrelated topic, which allegedly covers using stunnel to establish a TLS connection first.

After searching Google for stunnel azure redis, I found a link to some documentation that describes two methods of connecting to Azure Redis:

  1. Disable TLS (not recommended, for obvious reasons)
  2. Use stunnel to establish a TLS connection

I chose to install stunnel on Windows Subsystem for Linux (WSL) instead of using the Windows version of stunnel.

sudo apt-get install stunnel

Then, I created a configuration file that points stunnel to my Azure Redis Cache.

foreground = yes

[redis-cli]
client = yes
accept = 127.0.0.1:6380
connect = mytestcache658.redis.cache.windows.net:6380

Then I simply run stunnel in the foreground, using a separate tmux pane, referencing the configuration file.

stunnel stunnel.conf

In another tmux pane, I run redis-cli and connect to the remote Azure Redis Cache. You can either specify the primary key / password using the -a parameter, or you can connect anonymously and then use the auth REDACTED command in redis-cli to authenticate.

redis-cli -p 6380 -a REDACTEDREDACTED

or

redis-cli -p 6380
redis> AUTH REDACTED

Upvotes: 1

Related Questions