Before we start learning about Redis and how we can leverage on its fast performance, we need to install and have a working server. The installation of Redis is easy and straightforward.
In order to install, we need a computer system with a working Linux environment or a Mac OS X. If using Linux, I assume you have installed the Debian or Ubuntu operating system for this book. For the other operating system, you can refer to the There's more section of this recipe. As the Debian or Ubuntu packages are usually outdated, we will see how to install the Redis server from the source. Make sure you are using the latest stable version, as Redis is under active development and new commands and improvements pop out in every version. There are no dependencies for the Redis server except libc
, which will be available in your system by default. But to build the server from the source, you need the compiler.
# sudo apt-get update
# sudo apt-get install build-essential
# wget http://download.redis.io/redis-stable.tar.gz # tar xvzf redis-stable.tar.gz # cd redis-stable # make # sudo make install
Building a Redis server from the source is easy and it gets the latest version. The preceding steps will download the latest version of Redis from the repository, compile the C source, and install them in the machine. In this section, we will understand about various executables generated in this process.
You can install any unstable builds using the same procedure.
On successful execution of the preceding procedure, the following binaries are built from the source:
Now that we have built the Redis binaries from the source, we will see how to set up the Redis server with configuration files and test the installation.
The make install
command copies all the executables to the/usr/local/bin
folder. The configuration files and init scripts are not yet in place to run Redis.
install_server.sh
script, which can be found inside the utils
folder of the Redis source. In the terminal, go to the utils
folder inside redis-stable
and execute the following command:# ./install_server.sh
/etc/redis/6379.conf
. Run redis-cli
to test the server in another terminal window.# redis-cli
redis 127.0.0.1:6379>
SET Android Google SET Windows Microsoft SET iOS Apple
string
(Android, Windows, and iOS) and set their values to their respective company names. To check the server, issue the GET
command using the keys created to retrieve their values.GET Android Google GET iOS Apple QUIT
QUIT
command closes the connection from the server. To stop the server, issue the following command. Using shutdown
makes sure that Redis saves the data to the disk before quitting gracefully.# redis-cli shutdown
Now we have a working Redis server with the basic configuration.
If you are using Mac OS X, you can install Redis from the source or by using Homebrew. The installation process from the source is the same as we did for Debian. So we will see how to install Redis in Mac using Homebrew. You should have OS X command-line tools installed in the system for Homebrew to work. If you do not have the command-line tools installed, you can download them from the Apple Developer website (http://connect.apple.com/).
ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)
brew doctor
brew install redis
Homebrew installs and configures the server. You can test the installation by running redis-cli
and issuing commands to the server.
If you are a loyal user of the Windows operating system, you have hit a hurdle. Unfortunately, Redis is not officially supported in Windows 32- or 64-bit systems. But there are various ports available that are not of production quality and can be used only for development purposes. As Redis is not natively supported in Windows, the performance of ported builds is not even close to its performance in Linux. But if you do not have access to Linux systems, the compiled packages can be downloaded from the GitHub page of the officially recommended Windows port (https://github.com/dmajkic/redis/downloads).
As it is not officially supported for Windows, the book will focus on the Linux installation, and using a Linux system is strongly recommended.
3.145.175.253