Skip to content
Advertisement

Can I use Redis installed on Windows Subsystem for Linux with a python app in Windows?

I would like to develop a python application on Windows that will use Redis as a broker for Celery. Is it correct to assume that my application can interact with an instance of Redis that I have installed on the Windows Subsystem for Linux?

I have enabled the Windows Subsystem for Linux on Windows 10, and installed Ubuntu and Redis onto it, and started the server. On the Windows side, I’m using VSCode to write the python code. As shown below, in my python code, I am trying to connect to Redis on localhost:6379

JavaScript

I am trying to confirm whether my Python code, written in Windows, can interact with the Redis server being run on Ubuntu. Is this possible, and if so how can I confirm the connection?

Advertisement

Answer

Yes, you can use redis from wsl from windows. First, make sure you’ve installed and started the redis service:

JavaScript

if you already run a redis server on windows, you’ll need to edit the port directive in /etc/redis/redis.conf (e.g. to 7379 like I’ve done for the commands below).

Then start the service

JavaScript

and then run redis-cli and issue the monitor command (you can skip the -p 7379 if you’re using the default port):

JavaScript

now, from your windows command prompt, install the redis module from pypi (https://pypi.org/project/redis/):

JavaScript

then start python and issue a test command (again, use 6379 if you’re using the default port):

JavaScript

in your wsl session you should now see something like:

JavaScript

Note: redis is not fuzzy about where the server is. If you have the cli tools installed on windows you can issue commands from dos to the server running on wsl:

JavaScript

and vice-versa (redis-cli on wsl will happily connect to a redis service running on windows — which is how I discovered I needed to specify different ports ;-)

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement