logo资料库

Redis in Action.pdf

第1页 / 共322页
第2页 / 共322页
第3页 / 共322页
第4页 / 共322页
第5页 / 共322页
第6页 / 共322页
第7页 / 共322页
第8页 / 共322页
资料共322页,剩余部分请下载后查看
Redis in Action
brief contents
contents
foreword
preface
acknowledgments
about this book
Roadmap
Code conventions and downloads
Author Online
About the author
about the cover illustration
Part 1: Getting started
Chapter 1: Getting to know Redis
1.1 What is Redis?
1.1.1 Redis compared to other databases and software
1.1.2 Other features
1.1.3 Why Redis?
1.2 What Redis data structures look like
1.2.1 Strings in Redis
1.2.2 Lists in Redis
1.2.3 Sets in Redis
1.2.4 Hashes in Redis
1.2.5 Sorted sets in Redis
1.3 Hello Redis
1.3.1 Voting on articles
1.3.2 Posting and fetching articles
1.3.3 Grouping articles
1.4 Getting help
1.5 Summary
Chapter 2: Anatomy of a Redis web application
2.1 Login and cookie caching
2.2 Shopping carts in Redis
2.3 Web page caching
2.4 Database row caching
2.5 Web page analytics
2.6 Summary
Part 2: Core concepts
Chapter 3: Commands in Redis
3.1 Strings
3.2 Lists
3.3 Sets
3.4 Hashes
3.5 Sorted sets
3.6 Publish/subscribe
3.7 Other commands
3.7.1 Sorting
3.7.2 Basic Redis transactions
3.7.3 Expiring keys
3.8 Summary
Chapter 4: Keeping data safe and ensuring performance
4.1 Persistence options
4.1.1 Persisting to disk with snapshots
4.1.2 Append-only file persistence
4.1.3 Rewriting/compacting append-only files
4.2 Replication
4.2.1 Configuring Redis for replication
4.2.2 Redis replication startup process
4.2.3 Master/slave chains
4.2.4 Verifying disk writes
4.3 Handling system failures
4.3.1 Verifying snapshots and append-only files
4.3.2 Replacing a failed master
4.4 Redis transactions
4.4.1 Defining users and their inventory
4.4.2 Listing items in the marketplace
4.4.3 Purchasing items
4.5 Non-transactional pipelines
4.6 Performance considerations
4.7 Summary
Chapter 5: Using Redis for application support
5.1 Logging to Redis
5.1.1 Recent logs
5.1.2 Common logs
5.2 Counters and statistics
5.2.1 Storing counters in Redis
5.2.2 Storing statistics in Redis
5.2.3 Simplifying our statistics recording and discovery
5.3 IP-to-city and -country lookup
5.3.1 Loading the location tables
5.3.2 Looking up cities
5.4 Service discovery and configuration
5.4.1 Using Redis to store configuration information
5.4.2 One Redis server per application component
5.4.3 Automatic Redis connection management
5.5 Summary
Chapter 6: Application components in Redis
6.1 Autocomplete
6.1.1 Autocomplete for recent contacts
6.1.2 Address book autocomplete
6.2 Distributed locking
6.2.1 Why locks are important
6.2.2 Simple locks
6.2.3 Building a lock in Redis
6.2.4 Fine-grained locking
6.2.5 Locks with timeouts
6.3 Counting semaphores
6.3.1 Building a basic counting semaphore
6.3.2 Fair semaphores
6.3.3 Refreshing semaphores
6.3.4 Preventing race conditions
6.4 Task queues
6.4.1 First-in, first-out queues
6.4.2 Delayed tasks
6.5 Pull messaging
6.5.1 Single-recipient publish/subscribe replacement
6.5.2 Multiple-recipient publish/subscribe replacement
6.6 Distributing files with Redis
6.6.1 Aggregating users by location
6.6.2 Sending files
6.6.3 Receiving files
6.6.4 Processing files
6.7 Summary
Chapter 7: Search-based applications
7.1 Searching in Redis
7.1.1 Basic search theory
7.1.2 Sorting search results
7.2 Sorted indexes
7.2.1 Sorting search results with ZSETs
7.2.2 Non-numeric sorting with ZSETs
7.3 Ad targeting
7.3.1 What’s an ad server?
7.3.2 Indexing ads
7.3.3 Targeting ads
7.3.4 Learning from user behavior
7.4 Job search
7.4.1 Approaching the problem one job at a time
7.4.2 Approaching the problem like search
7.5 Summary
Chapter 8: Building a simple social network
8.1 Users and statuses
8.1.1 User information
8.1.2 Status messages
8.2 Home timeline
8.3 Followers/following lists
8.4 Posting or deleting a status update
8.5 Streaming API
8.5.1 Data to be streamed
8.5.2 Serving the data
8.5.3 Filtering streamed messages
8.6 Summary
Part 3: Next steps
Chapter 9: Reducing memory use
9.1 Short structures
9.1.1 The ziplist representation
9.1.2 The intset encoding for SETs
9.1.3 Performance issues for long ziplists and intsets
9.2 Sharded structures
9.2.1 HASHes
9.2.2 SETs
9.3 Packing bits and bytes
9.3.1 What location information should we store?
9.3.2 Storing packed data
9.3.3 Calculating aggregates over sharded STRINGs
9.4 Summary
Chapter 10: Scaling Redis
10.1 Scaling reads
10.2 Scaling writes and memory capacity
10.2.1 Handling shard configuration
10.2.2 Creating a server-sharded connection decorator
10.3 Scaling complex queries
10.3.1 Scaling search query volume
10.3.2 Scaling search index size
10.3.3 Scaling a social network
10.4 Summary
Chapter 11: Scripting Redis with Lua
11.1 Adding functionality without writing C
11.1.1 Loading Lua scripts into Redis
11.1.2 Creating a new status message
11.2 Rewriting locks and semaphores with Lua
11.2.1 Why locks in Lua?
11.2.2 Rewriting our lock
11.2.3 Counting semaphores in Lua
11.3 Doing away with WATCH/MULTI/EXEC
11.3.1 Revisiting group autocomplete
11.3.2 Improving the marketplace, again
11.4 Sharding LISTs with Lua
11.4.1 Structuring a sharded LIST
11.4.2 Pushing items onto the sharded LIST
11.4.3 Popping items from the sharded LIST
11.4.4 Performing blocking pops from the sharded LIST
11.5 Summary
appendix A: Quick and dirty setup
A.1 Installation on Debian or Ubuntu Linux
A.2 Installing on OS X
A.3 Installing on Windows
A.3.1 Drawbacks of Redis on Windows
A.3.2 Installing Redis on Windows
A.3.3 Installing Python on Windows
A.4 Hello Redis
appendix B: Other resources and references
B.1 Forums for help
B.2 Introductory topics
B.3 Queues and other libraries
B.4 Data visualization and recording
B.5 Data sources
B.6 Redis experiences and articles
index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Z
IN ACTION Josiah L. Carlson FOREWORD BY Salvatore Sanfilippo www.it-ebooks.info M A N N I N G
Redis in Action www.it-ebooks.info
www.it-ebooks.info
Redis in Action JOSIAH L. CARLSON M A N N I N G Shelter Island www.it-ebooks.info
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2013 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Development editor: Elizabeth Lexleigh Technical proofreaders: James Philips, Kevin Chang, and Nicholas Lindgren Java translator: Eric Van Dewoestine Copyeditor: Benjamin Berg Proofreader: Katie Tennant Typesetter: Gordan Salinovic Cover designer: Marija Tudor ISBN 9781935182054 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 18 17 16 15 14 13 www.it-ebooks.info
To my dear wife, See Luan, and to our baby girl, Mikela www.it-ebooks.info
www.it-ebooks.info
brief contents PART 1 GETTING STARTED . ..........................................................1 1 ■ Getting to know Redis 3 2 ■ Anatomy of a Redis web application 24 PART 2 CORE CONCEPTS.............................................................37 3 ■ Commands in Redis 39 4 ■ Keeping data safe and ensuring performance 63 5 ■ Using Redis for application support 90 6 ■ Application components in Redis 110 7 ■ Search-based applications 154 8 ■ Building a simple social network 185 PART 3 NEXT STEPS. ................................................................207 9 ■ Reducing memory use 209 10 ■ Scaling Redis 228 11 ■ Scripting Redis with Lua 249 vii www.it-ebooks.info
分享到:
收藏