Book Image

Redis Essentials

Book Image

Redis Essentials

Overview of this book

Redis is the most popular in-memory key-value data store. It's very lightweight and its data types give it an edge over the other competitors. If you need an in-memory database or a high-performance cache system that is simple to use and highly scalable, Redis is what you need. Redis Essentials is a fast-paced guide that teaches the fundamentals on data types, explains how to manage data through commands, and shares experiences from big players in the industry. We start off by explaining the basics of Redis followed by the various data types such as Strings, hashes, lists, and more. Next, Common pitfalls for various scenarios are described, followed by solutions to ensure you do not fall into common traps. After this, major differences between client implementations in PHP, Python, and Ruby are presented. Next, you will learn how to extend Redis with Lua, get to know security techniques such as basic authorization, firewall rules, and SSL encryption, and discover how to use Twemproxy, Redis Sentinel, and Redis Cluster to scale infrastructures horizontally. At the end of this book, you will be able to utilize all the essential features of Redis to optimize your project's performance.
Table of Contents (17 chapters)
Redis Essentials
Credits
About the Authors
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
5
Clients for Your Favorite Language (Become a Redis Polyglot)
Index

Installation


At the time of writing this book, the stable version of Redis was 3.0. All examples presented in this book will work with this version, but it is very likely that newer versions of Redis are going to work as well. Redis is very strict in terms of backward compatibility, so it provides API stability between minor versions. We recommend that you install the latest version of Redis to get the recent bug fixes and performance improvements. Most of the content in this book will remain useful even if you work with a more recent version.

Officially, Redis can be compiled and used on Linux, OS X, OpenBSD, NetBSD, and FreeBSD.

Redis is not officially supported on Windows. However, the Microsoft Open Tech group develops and maintains a Windows port targeting Win64 architecture, which can be found at https://github.com/MSOpenTech/redis. We are not going to cover Windows installation or guarantee that the examples presented in this book will work on Windows.

Installing from source

The first thing we need to do is open a terminal and run the following commands to download and install Redis. The following commands can be executed in any *nix operating system (Ubuntu, CentOS, Debian, OS X, and so on). Some build tools are required to build Redis from source (for example, gcc, make, and so on). On Ubuntu and Debian, these tools can be installed by the package build-essentials.

On OS X, you will need Xcode and Command Line Tools Package installed. After the required build tools are installed, open a terminal window and execute the following commands:

$ curl -O http://download.redis.io/releases/redis-3.0.2.tar.gz
$ tar xzvf redis-3.0.2.tar.gz
$ cd redis-3.0.2
$ sudo make install

Every time you see a dollar sign ($) at the beginning of a code block, it means we are executing the command in a terminal window.

Tip

Another way to install Redis is by using package managers, such as yum, apt, or brew. Make sure your package manager has Redis 3.0 or later available.