Cover
Copyright
Credits
About the Authors
Acknowledgments
About the Reviewers
www.PacktPub.com
Table of Contents
Preface
Chapter 1: Getting Started
(The Baby Steps)
Installation
Installing from source
Hello Redis (command-line interface examples)
Installing Node.js
JavaScript syntax quick reference guide
Hello World with Node.js and Redis
Redis data types
Strings
String examples with redis-cli
Building a voting system with Strings using Node.js
Lists
List examples with redis-cli
Implementing a generic Queue System
Hashes
Using Hashes with redis-cli
A voting system with Hashes and Node.js
Summary
Chapter 2: Advanced Data Types (Earning a Black Belt)
Sets
Set examples with redis-cli
Building a deal tracking system
Sorted Sets
Sorted Set examples with redis-cli
Building a leaderboard system for an
online game
Bitmaps
Bitmap examples with redis-cli
Building web analytics
HyperLogLogs
Counting unique users – HyperLogLog
versus Set
HyperLogLogs examples with redis-cli
Counting and retrieving unique
website visits
Summary
Chapter 3: Time Series (A Collection
of Observations)
Building the foundation
Optimizing with Hashes
Adding uniqueness with Sorted Sets and HyperLogLog
Summary
Chapter 4: Commands (Where the
Wild Things Are)
Pub/Sub
Transactions
Pipelines
Scripting
Lua syntax basics
Redis meets Lua
Miscellaneous commands
INFO
DBSIZE
DEBUG SEGFAULT
MONITOR
CLIENT LIST and CLIENT SET NAME
CLIENT KILL
FLUSHALL
RANDOMKEY
EXPIRE and EXPIREAT
TTL and PTTL
PERSIST
SETEX
DEL
EXISTS
PING
MIGRATE
SELECT
AUTH
SCRIPT KILL
SHUTDOWN
OBJECT ENCODING
Data type optimizations
String
List
Set
Hash
Sorted Set
Measuring memory usage
Summary
Chapter 5: Clients for Your
Favorite Language
(Become a Redis Polyglot)
PHP
The basic commands in PHP
The blocking commands in PHP
Pipelines in PHP
Transactions in PHP
Scripting in PHP
Python
The basic commands in Python
The blocking commands in Python
Pipelines in Python
Transactions in Python
Scripting in Python
Ruby
The basic commands in Ruby
The blocking commands in Ruby
Pipelines in Ruby
Transactions in Ruby
Scripting in Ruby
Summary
Chapter 6: Common Pitfalls
(Avoiding Traps)
The wrong data type for the job
The Set approach
The Bitmap approach
Multiple Redis databases
Keys without a namespace
Using Swap
Not planning and configuring the memory properly
An inappropriate persistence strategy
Summary
Chapter 7: Security Techniques
(Guard Your Data)
The basic security
Obfuscating critical commands
Networking security
Protecting Redis with firewall rules
Running Redis on the loopback network interface
Running Redis in a Virtual Private Cloud
Encrypting client-to-server communication
Running stunnel on both the server and
the client
Running stunnel on the server and using
a Redis client that supports SSL
Summary
Chapter 8: Scaling Redis
(Beyond a Single Instance)
Persistence
RDB (Redis Database)
AOF (Append-only File)
RDB versus AOF
Replication
Partitioning
Range partitioning
Hash partitioning
Presharding
Consistent hashing
Tagging
Data store versus cache
Implementations of Redis partitioning
Automatic sharding with twemproxy
Other architectures that use twemproxy
Summary
Chapter 9: Redis Cluster and
Redis Sentinel
(Collective Intelligence)
The CAP theorem
Redis Sentinel
The basic Sentinel configuration
Connecting to Sentinel
Network partition (split-brain)
Redis Cluster
Hash slots
Hash tags
Creating a basic cluster
Finding nodes and redirects
Configuration
Different Redis cluster architectures
Cluster administration
Creating a cluster
Adding slaves/replicas
Scaling reads using slave nodes
Adding nodes
Removing nodes
Redis cluster administration using the redis-trib tool
Summary
Index