How to Install Redis on MacOS with Curl
Redis a fantastic free and open-source in-memory key-value database that can be used to cache your web app to improve both performance and resource consumption. Today I will go over how we can install and run Redis locally on your Mac.
Installing Redis for macOS is not as straight forward as downloading a .dmg and clicking it. However, we have a few options available to choose from. We can download the binary from the download section of redis.io, or use homebrew, wget or Curl.
Personally, I am not a big fan of homebrew, even though it might be the most common way of downloading packages via the terminal for mac. So I thought I'd share how we can install Redis using Curl.
Here is a quick overview of the commands used to install Redis with Curl for mac. the less seasoned developers can find a more in-depth section below.
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
1. Create a folder for Redis and navigate to it
Open up a new terminal window and run the command..
mkdir redis && cd redis
This command will create a folder in your user folder (/Users/username) called "redis" and then navigate to it.
2. Download the stable Redis tar.gz with Curl
curl -O http://download.redis.io/redis-stable.tar.gz
3. Unpack redis-stable.tar.gz
tar xzvf redis-stable.tar.gz
4. Navigate to the unpacked redis-stable folder
5. Compile Redis
With the make command we can compile the binaries.
6. Test the compilation
With the make test you can verify that everything was built correctly. Be away that the test can take a few minutes to run..
Testing integration/aof [ok]: Unfinished MULTI: Server should start if load-truncated is yes [ok]: Check for memory leaks (pid 10969) [ok]: Short read: Server should start if load-truncated is yes [ok]: Truncated AOF loaded: we expect foo to be equal to 5 [ok]: Append a new command after loading an incomplete AOF [ok]: Check for memory leaks (pid 10985) [ok]: Short read + command: Server should start [ok]: Truncated AOF loaded: we expect foo to be equal to 6 now [ok]: Check for memory leaks (pid 11001) [ok]: Bad format: Server should have logged an error [ok]: Unfinished MULTI: Server should have logged an error [ok]: Short read: Server should have logged an error [ok]: Short read: Utility should confirm the AOF is not valid [ok]: Short read: Utility should be able to fix the AOF [ok]: Fixed AOF: Server should have been started [ok]: Fixed AOF: Keyspace should contain...
If make test was successfull you should be greeted with...
\o/ All tests passed without errors!
7. Finally install Redis
We are almost finished, as it is time to install Redis, we can do so with the command..
sudo make install
If your terminal is outputting 5 lines of "INSTALL install" you should be good to go!
INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install
8. Verify that everything is setup correctly
Now when everything is installed you should be able to start your Redis server with the command..
.. and be greetd with the following prompt :D
_._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.9 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 12192 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 12192:M 26 Apr 2020 11:14:27.094 # Server initialized 12192:M 26 Apr 2020 11:14:27.095 * Ready to accept connections
You should now also have access to the redis CLI.
which should give you your redis-servers IP...
.. and to be 100% that everything is good you can ping it.
And you will be greated with a PONG.
That's really all there is to it! In the next tutorial regarding Redis I will dig deeper into how we can use it as a key-value store Cache for Django ORM.