You are previewing Redis Essentials.
O'Reilly logo
Redis Essentials

Book Description

Harness the power of Redis to integrate and manage your projects efficiently

About This Book

  • Learn how to use Redis's data types efficiently to manage large data sets

  • Scale Redis to multiple servers with Twemproxy, Redis Sentinel, and Redis Cluster

  • A fast-paced guide, full of real-world examples to help you get the best out of the features offered by Redis

  • Who This Book Is For

    If you are a competent developer with experience of working with data structure servers and want to boost your project's performance by learning about features of Redis, then this book is for you.

    What You Will Learn

  • Build analytics applications using Bitmaps and Hyperloglogs

  • Enhance scalability with Twemproxy, Redis Sentinel, and Redis Cluster

  • Build a Time Series implementation in Node.js and Redis

  • Create your own Redis commands by extending Redis with Lua

  • Get to know security techniques to protect your data (SSL encryption, firewall rules, basic authorization)

  • Persist data to disk and learn the trade-offs of AOF and RDB

  • Understand how to use Node.js, PHP, Python, and Ruby clients for Redis

  • Avoid common pitfalls when designing your next solution

  • In Detail

    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.

    Style and approach

    A practical guide that offers the foundation upon which you can begin to understand the capabilities of Redis using a step-by-step approach. This book is full of real-world problems and in-depth knowledge of the concepts and features of Redis, with plenty of examples.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

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