Downloading and installing Redis
Redis has an active community on GitHub. Large numbers of pull requests have been made and merged during the years, and the author, Antirez, has always given a timely response on the issues section in GitHub. Hence, the release cycles of Redis are very rapid. From the early versions, 2.6/2.8 to 3.0/3.2, which were widely used, and then to the latest 4.x version, each release of Redis offers some essential enhancements and bug fixes. So using the latest version of Redis, if possible, is one of the best practices. In this book, we are adopting the latest version of Redis 4.0.1.
Redis is an open software written in pure C language so that we can install it by compilation. Major operating systems also include Redis binary packages in their software repository, although the Redis version is often a little out of date.
Getting ready…
You can find the download link and basic installation steps at https://redis.io/download. If you would like to build Redis by compiling source code in Linux/Unix/macOS, both the gcc compiler and C Standard Library libc are needed in your environment. When it comes to OS repository installation, all you need are an internet connection and the correct repository configuration.
How to do it...
We will demonstrate the compilation installation of Redis in Ubuntu 16.04.2 LTS (Xenial Xerus). The downloading and building steps are as follows:
- Set up building tools:
$ sudo apt-get install build-essential
- Create a directory and enter it for Redis:
$ mkdir /redis
$ cd /redis
- Then, download Redis:
$ wget http://download.redis.io/releases/redis-4.0.1.tar.gz
- Untar it and enter the directory:
$ tar zxvf redis-4.0.1.tar.gz
$ cd redis-4.0.1
- Create a directory for the Redis configuration file and copy the default configuration file into it:
$ mkdir /redis/conf
$ cp redis.conf /redis/conf/
- Building dependencies:
$ cd deps
$ make hiredis lua jemalloc linenoise
$ cd ..
Note
Due to the differences among various operation systems and libraries installed on it, the aforementioned steps will be required when errors occur indicating some dependencies are not satisfied. For example, you may encounter the error message:zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory.
This step is not a must for most environments, if nothing about dependencies goes wrong.
- Do the compilation:
$ make
If everything goes well, the following message will be shown. It means that the compilation has been done successfully:
It's a good idea to run 'make test' ;)
make[1]: Leaving directory '/redis/redis-4.0.1/src'
- Install Redis:
$ make PREFIX=/redis install
The following messages represent the success of installation:
- Enter the
/redis
directory and verify that the Redis binary files have been generated:
$ ls /redis/bin
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server
Congratulations! You have completed the Redis compilation installation.
Compared to the compilation installation, using apt-get
in Ubuntu to install Redis is much easier. Let's take a look:
- First, update software repository index:
$ sudo apt-get update
- And then start the installation:
$ sudo apt-get install redis-server
- When it's finished, check if Redis has been set up in your environment:
$ which redis-server
How it works...
When it comes to the Redis version selection, bear in mind that Redis follows the standard practice of versioning, which is major.minor.patch level. An even-numbered minor stands for a stable release, while an odd-numbered minor means it's an unstable version, although there are a few versions using an odd minor for Redis.
The differences between building Redis by compiling and building via a software repository, are that the former can add optimization or debugging options when compiling, and also own the flexibility of specifying the installation location during installation.
After installation, there are some executable files in the bin
directory. Their description and remarks are shown in the following table:
File name | Description | Remarks |
| Redis Server |
|
| Redis Sentinel | A soft link for |
| Redis Console Tool |
|
| Redis RDB Check Tool |
|
| Redis Append Only Files (AOF) Check Tool |
|
| Redis Benchmarking Tool |
|
There's more...
For Windows, you can obtain the Redis release of Windows, which the Microsoft Open Technologies group used to maintain at: https://github.com/MicrosoftArchive/redis/releases.
Just download the .msi
executable file and give it a double-click to install, keeping the default configurations.
For macOS, there is no big difference from the procedures in Linux. You can also install Redis by issuing the command, brew install redis
on macOS.
See also
- For the impact of different compilation options on Redis performance, refer to Matt Stancliff's evaluation of Redis performance for different versions by taking different compilation options: https://matt.sh/redis-benchmark-compilers
- For security concerns, a non-root user should be used for Redis and the Securing Redis recipe in Chapter 8, Deploying to a Production Environment will have a detailed discussion
- You can further refer to https://github.com/antirez/redis for more information