DEV Community

Cover image for How to install Redis on Windows?
Aria Azadi Pour
Aria Azadi Pour

Posted on • Updated on

How to install Redis on Windows?

In this article I'm going to teach you how you can use the latest version of Redis on windows using WSL or docker. We will use three different ways to install and use Redis on Windows.

What is Redis?

Redis is an open-source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

redis logo

How to use Redis on Windows?

I will teach you three ways to install and use Redis on Windows.

  1. Using WSL(Debian based(eg. Ubuntu)) only
  2. Using WSL and Docker together
  3. Using Docker only

My preferred method is using docker only it will work perfectly and the only thing you need is to install Docker.

What is WSL?

The Windows Subsystem for Linux lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup.

You can:

  • Choose your favorite GNU/Linux distributions from the Microsoft Store.
  • Run common command-line tools such as grep, sed, awk, or other ELF-64 binaries.
  • Run Bash shell scripts and GNU/Linux command-line applications including:
    • Tools: vim, emacs, tmux
    • Languages: NodeJS, Javascript, Python, Ruby, C/C++, C# & F#, Rust, Go, etc.
    • Services: SSHD, MySQL, Apache, lighttpd, MongoDB, PostgreSQL.
  • Install additional software using your own GNU/Linux distribution package manager.
  • Invoke Windows applications using a Unix-like command-line shell.
  • Invoke GNU/Linux applications on Windows.

wsl(windows + linux)

What is Docker?

In 2013, Docker introduced what would become the industry standard for containers. Containers are a standardized unit of software that allows developers to isolate their app from its environment, solving the “it works on my machine” headache. For millions of developers today, Docker is the de facto standard to build and share containerized apps - from desktop, to the cloud. We are building on our unique connected experience from code to cloud for developers and developer teams.

docker logo

Using WSL only

In this method, you need to install WSL and a Debian-based OS like Ubuntu on WSL and then open the terminal to start our work. After installing the OS you can follow the process below to start your own redis-server on Windows and use it with redis-cli.

1.As always before installing a new tool we need to update and upgrade our system you can do it with the commands below:



  $ sudo apt update && apt upgrade


Enter fullscreen mode Exit fullscreen mode

2.Then you need to install redis-server package on your subsystem:



  $ sudo apt install redis-server


Enter fullscreen mode Exit fullscreen mode

3.Now you need to start redis-server in order to work with Redis:



  $ sudo service redis-server start


Enter fullscreen mode Exit fullscreen mode

4.Finally you can run redis-cli in order to test and use Redis:



  $ redis-cli


Enter fullscreen mode Exit fullscreen mode

Note that you need to press (CTRL/OPT)+C or use the exit command in order to close the redis-cli.

Redis by default uses port 6379 if the port is not empty the service will not get started.

Redis configuration file is located at /etc/redis/redis.conf if you need to edit any configuration. (you need sudo access in order to read or write the file)

Using WSL and Docker together

In this method like the previous method first, you need to install WSL but you can install your OS of choice, for example, I will use Manjaro in this tutorial. After that, you need to install Docker and enable WSL integration for your OS of choice.

you can enable WSL integration for your OS of choice by opening Docker Desktop and going to Settings>Resources>WSL Integration and from there you can switch on your OS of choice.

1.First you need to create the Redis container and expose port 6379:



  $ docker container run --name container-name -p 6379:6379 -d redis


Enter fullscreen mode Exit fullscreen mode

docker container run will make docker create and run a new container.

--name flag will specify the name of the container so you can change container-name to your name of choice.

-p flag will tell docker to expose a port from container to computer, in this case, is the Redis default port.

-d flag will start the container in the detach mode so the container won't stop when we close our terminal.

2.Then you need to update and upgrade your packages before installing the redis-cli.



  $ sudo apt update && apt upgrade


Enter fullscreen mode Exit fullscreen mode

3.After that you need to install redis-cli using your OS package manager, in my case pacman:



  $ sudo pacman -S redis


Enter fullscreen mode Exit fullscreen mode

note that redis-cli will usually come with another package like redis or redis-server.

note that redis package names can be different in different package managers so if you are using some other OS you can do a google search and find out the name of the package for your OS.

Using Docker only

In this method unlike the other two, you don't have to install WSL and the only thing you have to do is install Docker.

1.First you need to create the Redis container and expose port 6379:



  $ docker container run --name container-name -p 6379:6379 -d redis


Enter fullscreen mode Exit fullscreen mode

docker container run will make docker create and run a new container.

--name flag will specify the name of the container so you can change container-name to your name of choice.

-p flag will tell docker to expose a port from container to computer, in this case, is the Redis default port.

-d flag will start the container in the detach mode so the container won't stop when we close our terminal.

And finally the Redis means use the Redis image.

2.Finally you can run redis-cli using docker:



  $ docker container run -it --link container-name:redis --rm redis redis-cli -h redis -p 6379


Enter fullscreen mode Exit fullscreen mode

-it flag will make docker open an interactive instance of the container.

--link flag will link the container we previously created as Redis in this container.

Note that you should change container-name with the name you chose in the first command.

--rm flag will make docker remove the container after we close it. (This is useful cause we will no longer need this container after we ran redis-cli command)

Same as before Redis means use the Redis image.

redis-cli -h redis -p 6379 is the command docker will run for us.

In the redis-cli command -h specifies the host which we set it to redis using --link flag.

And finally in the redis-cli command -p specifies the port which is by default 6379.

Resources

Find Me

Top comments (2)

Collapse
 
sskanishk profile image
Kanish Malviya

out of 3 which one should be consider ?

Collapse
 
devaddict profile image
Aria Azadi Pour

Using docker is the best way in my opinion. You can use the latest version and create new databases in no time.