Redis is a well-known key value type database that saves data into memory. In this tutorial, we will learn how to install redis on windows and understand other vital concepts regarding redis on windows. so let’s get started.
Install redis on windows
By default, redis does not support installation on windows but there are a few workarounds that users can use to install redis on windows.
To install Redis on Windows, users need to enable WSL2(Windows Subsystem for Linux).WSL2 let users run native Linux binaries on Windows
Install/enable WSL2 on windows to install redis
To install WSL2, the user needs to have Windows 10 version 2004 and higher. Type the below command in the windows power shell to install wsl2.
wsl --install
Once the wsl is installed, you can type the below command to check the version of wsl installed.
wsl -l -v
You can follow the below this link to get more information about installing wsl on windows.
Install redis on windows using WSL2
Once the wsl2 is installed on the windows machine it will start a ubuntu instance of Linux libraries on windows. Now type the below command to add the repo to the apt
index
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
Now update and install the redis using the above repo which we have added.
sudo apt-get update
sudo apt-get install redis
Install redis on windows using Snapcraft
Users can also install redis using the Snapcraft package. If the Linux kernel does not have snapcraft installed then the user can follow this link to install a snap.
Type the below command to install redis using snap
sudo snap install redis
Check redis service on windows
Type the below command to check if the redis service is running on windows
sudo service redis-server status
If the service is not running, type the below command to start the redis service.
sudo service redis-server start
Redis windows port
By default, redis is running on port 6379 on windows and the user can change this port by editing the redis.windows.conf file.
# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
Users need to restart the redis service after changing the port
sudo service redis-server restart
redis-cli windows
Redis-cli will behave the same irrespective of whether redis is installed on windows or on any other Linux distribution. By default redis-cli
connects to 127.0.0.1 and port 6379. Type the below command to connect to redis cli.
redis-cli -h 127.0.0.1 -p 6379
Type the ping command to verify if the redis installation is working fine
127.0.0.1:6379> ping
PONG
if you are getting PONG as output it means your redis installation is working fine.
You can check my below tutorial on redis to get comfortable with redis.
Python redis windows
Users can also interact with redis using the python client library. Type the below command to install the redis client library using pip
pip install redis
once the redis library is installed the user can use the below code snipped to connect to redis
import redis
redis = redis.Redis(host= 'localhost',port= '6379')
redis.set('key1', 'value1')
value = redis.get('key1')
print(value)
More information about the redis python client can be found here
Conclusion
I hope you have liked this tutorial about the redis installation on windows. In this blog, we have learned different methods to install redis on windows. We also understood how to connect to redis cli and about the redis port and how to change it. Finally, we have learned about the redis python client.
Please do let me know if you are facing any issues while following along.