Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Redis 4.x Cookbook

You're reading from   Redis 4.x Cookbook Over 80 hand-picked recipes for effective Redis development and administration

Arrow left icon
Product type Paperback
Published in Feb 2018
Publisher Packt
ISBN-13 9781783988167
Length 382 pages
Edition 1st Edition
Tools
Arrow right icon
Authors (2):
Arrow left icon
Zuofei Wang Zuofei Wang
Author Profile Icon Zuofei Wang
Zuofei Wang
Pengcheng Huang Pengcheng Huang
Author Profile Icon Pengcheng Huang
Pengcheng Huang
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Getting Started with Redis FREE CHAPTER 2. Data Types 3. Data Features 4. Developing with Redis 5. Replication 6. Persistence 7. Setting Up High Availability and Cluster 8. Deploying to a Production Environment 9. Administrating Redis 10. Troubleshooting Redis 11. Extending Redis with Redis Modules 12. The Redis Ecosystem 13. Windows Environment Setup
14. Other Books You May Enjoy

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: 

  1. Set up building tools:
$ sudo apt-get install build-essential 
  1. Create a directory and enter it for Redis:
$ mkdir /redis 
$ cd /redis 
  1. Then, download Redis:
$ wget http://download.redis.io/releases/redis-4.0.1.tar.gz 
  1. Untar it and enter the directory:
$ tar zxvf redis-4.0.1.tar.gz 
$ cd redis-4.0.1 
  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/ 
  1. Building dependencies:
$ cd deps 
$ make hiredis lua jemalloc linenoise 
$ cd .. 
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.
  1. 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' 
  1. Install Redis:
$ make PREFIX=/redis install 

The following messages represent the success of installation:

  1. 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:

  1. First, update software repository index:
$ sudo apt-get update 
  1. And then start the installation:
$ sudo apt-get install redis-server 
  1. 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 Server

redis-sentinel

Redis Sentinel

A soft link for redis-server.

redis-cli

Redis Console Tool

redis-check-rdb

Redis RDB Check Tool

redis-check-aof

Redis Append Only Files (AOF) Check Tool

redis-benchmark

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
You have been reading a chapter from
Redis 4.x Cookbook
Published in: Feb 2018
Publisher: Packt
ISBN-13: 9781783988167
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image