Connect to Redis server on ObjectRocket using WSL

Have a Database Problem? Speak with an Expert for Free
Get Started >>

Introduction

Windows Subsystem for Linux, typically referred to as WSL, is a newer compatibility layer designed to run Linux binary executable files on Windows 10 operating systems and servers. WSL is an optional feature that can be enabled via the Windows Features dialog. WSL allows for running native Linux command-line tools alongside traditional Windows applications. As Redis is not designed for Windows, the Windows Subsystem for Linux allows for increased compatibility between the two programs. This tutorial will provide explanations and examples on how to connect to the Redis server on ObjectRocket using WSL.

Prerequisite

  • An instance of Redis for an ObjectRocket’s account must be setup in the ObjectRocket Mission Control panel, shown in the following image:

Screenshot

  • The WSL, Redis and Stunnel software packages must be installed and configured correctly on the local device.

Install WSL on Windows

As Redis is not officially built for the Windows system, a tool is needed to bridge the gap between Redis and Windows. This section will cover installing the Windows Subsystem for Linux.

  • First, open PowerShell as an administrator and execute the following command:
1
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
  • Next, the above code will reboot the system to finish the installation process.

  • Lastly, install one of the supported Linux distribution from the Microsoft Store. In this case use Ubuntu 18.04 that allows for installing Redis v9.05.

Install Redis and Stunnel

With Ubuntu properly installed, now install Redis and Stunnel.

Stunnel is a proxy for secure tunnels that enables connection and interaction with other machines over TLS.

  • Begin by launching the ubuntu application:

Screenshot

Now execute the following commands:

  • sudo apt-get update — This command gets the necessary upgrade for the Linux distro.

  • sudo apt install Redis-tools stunnel4 — This command installs the Redis tools and the Stunnel4 update.

After installing stunnel4 and its updates, execute the following command to verify the program is running background:

service stunnel4 status.

The output should resemble the following:

1
TLS tunnels status: /etc/stunnel/stunnel.conf: running

Configuring Stunnel

Because the redis-cli is limited to a localhost connection only, Stunnel must be configured to bind it to the redis-cli, enabling a connection to a remote machine.

First, enable Stunnel by modifying the  /etc/default/stunnel via nano file in a text editor as shown here:

1
sudo nano /etc/default/stunnel4

Screenshot

Next, change the value to one (1) and then save and close the file.

Now create a configuration file for routing purposes.

First, open a new file called stunnel.conf under the /etc/stunnel directory.

Next, open the file named stunnel.conf inside the /etc/stunnel directory using nano, as shown here:

1
sudo nano /etc/stunnel/stunnel.conf

Now append the following:

1
2
3
4
5
6
7
8
9
fips = no
setuid = your user id or you can use root
setgid = your group id
pid = /var/run/stunnel.pid
debug = 7
[redis-cli]
  client = yes
  accept = localhost:8000
  connect = ingress.w98sujpz.launchpad.objectrocket.cloud:4102

The above configuration will bind the remote connection details of the Redis server instance on ObjectRocket to the localhost:8000 connection.

NOTE: The details for the connect command are from the server instance on ObjectRocket, shown here:

Screenshot

Connecting to a Redis Instance on ObjectRocket

Execute the following code to connect to the managed database:

1
redis-cli -h localhost -p 8000

Now authenticate the user with the auth command and then provide the password from the server instance found on the “CONNECT” tab on the ObjectRocket Mission Control panel.

Click on the eye icon shown below on the right to reveal the password for this instance.

Screenshot

Once authenticated, Redis will provide the following Ok prompt:

Screenshot

As shown in the above image, the basic operations of ping, setting up a key-value and retrieving the value were successful!

Conclusion

This tutorial provided explanations and examples on how to connect to the Redis server on ObjectRocket using WSL. The tutorial first provided instructions for installing and configuring the needed WSL, Redis and Stunnel software packages to connect to the Redis server on ObjectRocket using WSL. The article then gave an example of the code used to for connecting to a Redis Instance on ObjectRocket. Remember that the Redis command-line interface is limited to a localhost connection, making it imperative that Stunnel be properly configured to bind it to the Redis CLI to enable the connection to the remote machine.

Pilot the ObjectRocket Platform Free!

Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.

Get Started

Keep in the know!

Subscribe to our emails and we’ll let you know what’s going on at ObjectRocket. We hate spam and make it easy to unsubscribe.