Install Redis on Windows and Mac

Install Redis on Windows and Mac thumbnail
29K
By Dhiraj 29 June, 2019

In this article, we will be installing Redis data store on Windows and Mac OS. While installing Redis on Windows, we will be using Bash on Ubuntu on Windows application to set up the Redis locally. In the mac system, we will be using Homebrew as well as .tar file to install it. Once, the installation and setup is done, we will be using command lines to perform some get and put request to the Redis cache.

Installing Redis on Mac

Installing Redis using Homebrew on Mac

Homebrew is a package manager for Mac OS similar to apt-get in Linux for installing any software. If you don't have it installed on your Mac then you can follow this guide to install Homebrew. Once, installed you can execute below command on the termonal.

brew install redis

All the installation information can be found at /usr/local/Cellar/redis/5.0.5

Start Redis Service

There are two ways to start Redis server. Either you can start Redis as a service so that it will keep running in the background with the following command:

brew services start redis

Or, if you don't want a background service you can just run below command

  redis-server /usr/local/etc/redis.conf

Once, the Redis is started in the background, you can use brew services stop redis to stop the service. To uninstall the server, you can execute below command.

brew uninstall redis

And, to check if the Redis servicce is running, you can run redis-cli ping

Installing Redis Manually with .tar file on Mac

Homebrew is the best way to install any packages on mac but you can also download the zip file and manually install it. Below are the commands to install it manually.

  • mkdir redis && cd redis
  • curl -O http://download.redis.io/redis-stable.tar.gz
  • tar xzvf redis-stable.tar.gz
  • cd redis-stable
  • make
  • make test
  • sudo make install

Redis is implemented in C language and hence the .tar file has files with extension .c. After execution of the make command, files with extension .o will be generated.

To start the Redis, you can run the command redis-server.

Installing Redis on Windows

The Redis project does not officially support Windows. Hence, Bash on Ubuntu on Windows application is installed. You can follow this official documentation for Linux Installation Guide for Windows 10.

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Once, done you can run below commands to install Redis.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install redis-server
sudo service redis-server restart

Once, the Redis server is installed and running(default port 6379), we can use below command to test if Redis is running. The output will be PONG.

redis-cli ping

Common Commands

sudo service redis-server stop
sudo service redis-server start
sudo service redis-server restart

Common Redis Usage Command

Start Redis cli with the command redis-cli first before trying out below commands:

redis-cli -h 194.21.23.45 -p 16379 -a "password" //connect to remote redis server at 194.21.23.45 at 16379
 SET name dhiraj //adds a key value pair in Redis cache. Here the key is name and the value is dhiraj
 GET name         //Pulls value of supplied key 
 EXISTS name      //Checks if supplied key value pair exists. Outputs 1 if true
 DEL name         //Deletes the entry of given key if present
redis-cli-command-screenshot
Share

If You Appreciate This, You Can Consider:

We are thankful for your never ending support.

About The Author

author-image
A technology savvy professional with an exceptional capacity to analyze, solve problems and multi-task. Technical expertise in highly scalable distributed systems, self-healing systems, and service-oriented architecture. Technical Skills: Java/J2EE, Spring, Hibernate, Reactive Programming, Microservices, Hystrix, Rest APIs, Java 8, Kafka, Kibana, Elasticsearch, etc.

Further Reading on Devglan