logo资料库

Redis-Essentials.pdf

第1页 / 共230页
第2页 / 共230页
第3页 / 共230页
第4页 / 共230页
第5页 / 共230页
第6页 / 共230页
第7页 / 共230页
第8页 / 共230页
资料共230页,剩余部分请下载后查看
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
Redis Essentials Harness the power of Redis to integrate and manage your projects efficiently Maxwell Dayvson Da Silva Hugo Lopes Tavares BIRMINGHAM - MUMBAI
Redis Essentials Copyright © 2015 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: September 2015 Production reference: 1030915 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78439-245-1 www.packtpub.com
Credits Authors Maxwell Dayvson Da Silva Hugo Lopes Tavares Reviewers Gustavo Franco Chad Lung Stephen McDonald Yi Wang Commissioning Editor Sarah Crofton Acquisition Editor Harsha Bharwani Content Development Editor Kirti Patil Technical Editor Menza Mathew Copy Editor Vikrant Phadkay Project Coordinator Nidhi Joshi Proofreader Safis Editing Indexer Rekha Nair Production Coordinator Manu Joseph Cover Work Manu Joseph Cover Image Renata Pereira Rocha Moreira
About the Authors Maxwell Dayvson Da Silva, a self-taught programmer, is the director of technology at The New York Times. Born in Recife, Brazil, he is a video specialist and is most interested in bringing technology to a global audience. His work has ranged from developing and delivering highly scalable products to innovating and implementing large-scale video solutions. Prior to joining the Times, he worked for Globo, Brazil's leading media network, and Terra, a global digital media company. Additionally, he has spoken at conferences such as Campus Party, FISL, SET Broadcast and Cable, Streaming Media East, and Streaming Media West. Maxwell has also devoted time to speaking at several Brazilian universities, including UFGRS, IFRS, UDESC, and FEEVALE-RS. He is a contributor to and creator of some open source projects. You can find them at https://github.com/dayvson. Outside of his professional work, Maxwell regularly combines his passion for art and science to create games and interactive art installations. His son, Arthur, inspires him to seek opportunities to bring science into the lives of young people, both in New York and abroad. Although Redis Essentials is Maxwell's first book, he has done technical reviewing for two others, Extending Bootstrap and Learning JavaScript Data Structures and Algorithms. You can contact him on LinkedIn at http://www.linkedin.com/in/dayvson.
Hugo Lopes Tavares is a software developer from Brazil who currently works as a platform engineer at Yipit, a technology company focused on data aggregation and analysis. Prior to his work in the United States, Hugo worked on live streaming video development for Globo.com, the Internet branch of Grupo Globo, which is the largest media conglomerate in Latin America. Having been involved in open source software, he has made a significant impact in this field. He was a main contributor to pip (the Python package installer), wrote improvements to CPython and the Python standard library, coauthored Splinter (a web-testing tool), and contributed to many well-known projects. Some of his contributions can be found at https://github.com/hltbra. Additionally, Hugo worked at NSI (Information Systems Research Group), carrying out research and development on agile methods and software quality for the Brazilian government. Within his research, he created some testing tools, the most famous of which are Should-DSL and PyCukes, which are mentioned in Python Testing Cookbook, Packt Publishing (Should-DSL has its own section in it). When Hugo is not doing anything related to technology, he is involved in strength training as an amateur powerlifter. You can contact him on LinkedIn at https://www.linkedin.com/in/hltbra.
Acknowledgments I would like to express my gratitude for my amazing and supportive partner in crime and life, Karalyn Lathrop (a.k.a. KC). She was incredibly supportive and helpful in the making of this book in so many ways that I cannot describe how thankful I am for her. I am incredibly grateful to my son, Arthur, for being so amazingly sweet and funny. Also, thanks to him for making my life so much better, even with the long distance that keeps us far way. There are many people I'm thankful to for the making of this book: my mom, Mauriceia, for all the love that she has given me! My aunt, Maristela, for all the support and advice; the sweetest grandmothers, Alderita and Fran Kozina; and Juliane, for being a supermom and taking care of our son when I am far way. I give thanks to Nina Feinberg. Her help in this project was fundamental in improving the quality of the writing and consistency of this book. Also, I would like to give special acknowledgements to the many friends and colleagues who helped me during this journey. Each one of you made a significant contribution to this project, and I am so thankful: Lincoln Clarete, Cristian Taveras, Deep Kapadia, Flavio Ribeiro, Jose Muanis, Kentaro Kaji, Michael Sarullo, Manu Menezes, Gustavo Franco, and Renata Tavares. Finally, I give my huge thanks to Hugo Tavares for sharing this crazy experience with me. I'm honoured that he accepted my invite. Writing this book was challenging, exciting, and rewarding in so many ways. I had a lot of fun and learned a lot during the process. It's been an honour and privilege working with you. – Maxwell Dayvson Da Silva
I would like to thank my wife, Renata, for all her support and for designing a beautiful cover for this book. This project would not have succeeded without her support. Thanks, my love! I also thank my parents, Paulo and Maria das Graças, for always loving me, supporting my education and all my decisions, and giving me good advice on life. I am very thankful to Karalyn Lathrop and Nina Feinberg, who reviewed this book, and the technical reviewers. They improved this book's quality a lot. I also thank Maxwell Dayvson for inviting me to join him to write this great book. It has been an amazing experience, and I learned a lot by working with him. Thanks, my friend! I am very proud of both of us. – Hugo Lopes Tavares
分享到:
收藏