Running Redis on Windows via WSL

Running Redis on Windows via WSL

Port Forwarding Redis from Ubuntu 22.04 on WSL2 to it's Windows 11 host

I assume that you are on Windows 11.

If you want to install Redis on Windows and access redis data from a client application like redis-cli or using a script, we're out of options to do a classic Next Next Finish type of installation.

The current version of Redis stands at version 7.0.8 and there are no Windows binaries for Redis - at least not past version 3.2.100 available at

The official guide at Redis shows how to install Redis on WSL which is for example, running Ubuntu 22.04 on Windows Subsystem for Linux. But the last point "Connect to Redis" shows how to use redis-cli on the WSL itself.

But if we're developing our web apps on a Windows environment, even though we'll ultimately be deploying to a Linux server, we still would need to connect to the Redis Server running on Ubuntu at WSL from the Windows host.

From : Open PowerShell or Windows Command Prompt in administrator mode by right-clicking and selecting "Run as administrator", enter the wsl --install command, then restart your machine.

wsl --install

Now run wsl from the Start Menu - you should be into a Linux terminal.

sudo apt install lsb-release
curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

sudo apt-get update
sudo apt-get install redis

You would need to do sudo vi /etc/redis/redis.conf

Comment out bind ::1 in /etc/redis/redis.conf Comment out protected-mode yes and change it to protected-mode no

sudo service redis-server start

This is really not required since we edited the redis.conf file to include protected-mode no, but cross-check anyway :

$redis-cli> CONFIG GET protected*
(empty list or set)> CONFIG SET protected-mode no

$ifconfig - note down the inet value under eth0 - lets say it's - this is the tricky part - you need to update this IP address which is an internal dynamically generated IP at WSL each time you restart your laptop. Right now I don't know of a way to a fixed / static IP.

Back to the browser in Windows : Install NodeJS from - Download the latest LTS, as of now it's 18.14.2 - typical Next > Next > Next > Finish.

Open PowerShell and enter npm install -g redis-cli

This may or may not be required : Open PowerShell as Adminstrator and run :

netsh interface portproxy add v4tov4 listenport=6379 listenaddress= connectport=6379 connectaddress=

Close PowerShell (which we opened as Adminstrator)

Open PowerShell and enter : rdcli -h

PS C:\Users\John> rdcli -h> SET foo bar
OK> GET foo

Now let's get this working via PHP - I assume you have XAMPP.

Install PECL :
Download :

Copy the php_redis.dll file and paste it to C:\xampp\php\ext

Then edit C:\xampp\php\php.ini and add extension=php_redis.dll somewhere after extension=bz2

I assume this line is uncommented out : extension_dir="C:\xampp\php\ext"

Please read this if you're facing errors related to php_redis - - not only do you need to choose the right PECL release for redis for your PHP version - its different for PHP 7.2, PHP 7.4 and PHP 8.0. For PHP 7.4 it's 5.2.2 ( and for PHP 7.2 I had to download 3.1.4 from For PHP 8.x it should be 5.3.7.

Create a file on say D Drive (D:) and name it redis-test.php and enter :

$redis = new Redis(); 
$result = $redis->connect('', 6379); 
# print_r($result);

$redis->set("blogs", "hashnode,blogger,,medium"); 
echo "blogs string = " .$redis->get("blogs");

echo "\n";

$redis->set("blogs_json", json_encode(["hashnode" => "", "blogger" => "","" => "", "medium" => ""])); 

echo "blogs json = " .$redis->get("blogs_json");

echo "\n";

PS D:\> C:\xampp\php\php.exe .\redis-test.php
blogs string = hashnode,blogger,,medium
blogs json = {"hashnode":"","blogger":"","":"\/anjanesh","medium":"\/@anjanesh"}
stdClass Object
    [hashnode] =>
    [blogger] =>
    [] =>
    [medium] =>

If you find setting this up difficult, then try a remote Azure Redis Cache for which you just have to connect to the host and get the client (CLI or PHP script) to work with the data stored at Azure.

You can get 250 MB for $0.022/hour which, at the most, would amount to $15 a month if your localhost website were to be refreshed every hour for the whole month. So basically you'll be in the safe zone for localhost development amounting to ~$1 a month only. For testing purposes, it would be within a few cents. See Pricing details here.

Did you find this article valuable?

Support Anjanesh Lekshminarayanan by becoming a sponsor. Any amount is appreciated!