Connect to Redis server on ObjectRocket using WSL
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.
- An instance of Redis for an ObjectRocket’s account must be setup in the ObjectRocket Mission Control panel, shown in the following image:
- 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:
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:
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:
TLS tunnels status: /etc/stunnel/stunnel.conf: running
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
nano file in a text editor as shown here:
sudo nano /etc/default/stunnel4
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:
sudo nano /etc/stunnel/stunnel.conf
Now append the following:
fips = no
setuid = your user id or you can use root
setgid = your group id
pid = /var/run/stunnel.pid
debug = 7
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
NOTE: The details for the
connect command are from the server instance on ObjectRocket, shown here:
Connecting to a Redis Instance on ObjectRocket
Execute the following code to connect to the managed database:
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.
Once authenticated, Redis will provide the following
As shown in the above image, the basic operations of
ping, setting up a key-value and retrieving the value were successful!
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