Installing Redis on macOS and Windows can get a little confusing. It’s not always clear which commands you should use and what you need to install beforehand to make Redis work.
Follow this step-by-step guide to simplify the process. Once you install Redis, there are tips on optimizing it and answering frequently asked questions.
What Is Redis?
Redis, short for Remote Dictionary Server, is an open source, in-memory datastore. You can use it as a fast database, application cache solution, streaming engine, and more. Redis is a highly reliable, fast, and high-performing solution thanks to its ability to store data in RAM.
When applications rely on external data sources, they experience a significant latency, limiting their performance. To work around this limitation and improve application performance, you can store and operate on its data in RAM instead, bringing it closer to the application.
This solution is where Redis shines. It stores all the necessary external data in RAM to deliver the highest possible read and write performance. Furthermore, it enables replication to place data physically closer to reduce latency.
Here are some core features of Redis:
- Programmability using Lua and Redis Functions.
- Module API for writing custom Rust, C, and C++ extensions.
- Support for horizontal scalability with hash-based sharding.
- Replication with automatic failover.
- Ability to write to storage devices to survive shutdowns and reboots.
Install Redis on macOS
This section shows how to perform a macOS Redis installation. Start by installing Homebrew to make the whole process much easier.
Step 1: Install Xcode
Use the following command to install Xcode Command Line Tools. You will need this application to install Homebrew.
xcode-select --installStep 2: Install Homebrew
Use the following command to download the Homebrew installation from its official Git repository. You will need it to install Redis.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Follow the terminal instructions to complete the installation. This process will mostly consist of clicking y to proceed further.
Step 3: Install Redis
Use the following command to install Redis.
brew install redisStep 4: Start the Redis Service
Use the following command to activate the Redis service.
brew services start redisIf you see the startup logs in the output, you’ve successfully initiated Redis in the foreground.
Step 5: Test if Redis is Active
Use the following command to initiate the Redis command line.
redis-cliIf you see the following output, you’ve successfully initiated the Redis command line. The #.#.#.# represents your device’s IP, followed by a Redis port.
redis #.#.#.#:6379Now, type in the following command to test if Redis is running.
pingIf Redis is installed properly and active, you should see the following output.
PONGInstall Redis on Windows
While there’s no official support for Redis on Windows, you can still use it for development. To install Redis on Windows, you’ll need to use the Windows Subsystem for Linux (WSL), available if you’re running either Windows 10 version 2004 (or later) or Windows 11.
The following instructions assume you’ve chosen a recent version of Ubuntu for your WSL. It is also possible to install Redis on Ubuntu 16.04 and 18.04.
Developing with .NET?
Upgrade to top-notch support and performance with Liquid Web’s ASP.NET VPS hosting plans.
Step 1: Install Ubuntu
Open the Command Prompt app by typing cmd in search on the taskbar and then click the app’s icon. Now type in the following command to install Ubuntu and wait for it to complete.
wsl --install -d Ubuntu 22.04It will ask you to set a username and password and log into the Ubuntu terminal.
Step 2: Update Package Information
Use the following command to get the latest package information from your configured package sources.
sudo apt-get updateStep 3: Install Redis
Use the following command to install Redis.
sudo apt-get install redis-serverStep 4: Start the Redis Service
Use the following command to activate the Redis service.
sudo service redis-server startStep 5: Test if Redis is Active
Use the following command to initiate the Redis command line.
redis-cliIf you see the following output, you’ve successfully initiated the Redis command line. The #.#.#.# represents your device’s IP, followed by the Redis port.
redis #.#.#.#:6379Now, type in the following command to test if Redis is running.
pingIf Redis is properly installed and active, you should see the following output.
PONGTips for Optimizing Redis
Here are some tips for optimizing Redis.
Limiting memory usage
By default, Redis will keep allocating RAM as much as necessary and eventually take up all of it, causing your machine to run out of RAM. To prevent this, we recommend defining a custom maxmemory value in the Redis configuration file called redis.conf. The below example shows a maxmemory value of 2GB expressed in bytes.
maxmemory 8589934592Once you finish defining a custom memory limit, remember to restart the Redis service with the following commands.
If you’re using mac OS.
brew services restart redisIf you’re using Ubuntu.
sudo service redis-server restartMaking Redis Run on Startup
If you need Redis to start each time your operating system boots, follow the instructions below for your machine.
Use this command for mac OS.
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgentsThis command is for Ubuntu.
systemctl enable redis-server.serviceConclusion
Redis is a fast and reliable application cache and database solution that you can apply to various use cases. Some of its core features include programmability in Lua, support for custom extensions, horizontal scalability, and replication with automatic failover. If you want to set it up on a macOS or Windows machine, this guide gets you up and running quickly.
Once you are ready to deploy your next website or web application, Liquid Web is here to help. Choose one of the VPS hosting, cloud dedicated server, or dedicated server options, available with customizable server GPUs and CPUs. Contact the sales team for assistance in choosing the best fit.
Joseph Molloy