Redis 4.x Cookbook
Pengcheng Huang, Zuofei Wang
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Redis 4.x Cookbook
Pengcheng Huang, Zuofei Wang
About This Book
Leverage the power of Redis 4.x to develop, optimize and administer your Redis solutions with easeAbout This Book• Build, deploy and administer high performance and scalable applications in Redis• Covers a range of important tasks - including development and administration of Redis• A practical guide that takes your understanding of Redis to the next levelWho This Book Is ForThis book is for database administrators, developers and architects who want to tackle the common and not so common problems associated with the different development and administration-related tasks in Redis. A fundamental understanding of Redis is expected to get the best out of this book.What You Will Learn• Install and configure your Redis instance• Explore various data types and commands in Redis• Build client-side applications as well as a Big Data framework with Redis • Manage data replication and persistence in Redis• Implement high availability and data sharding in Redis• Extend Redis with Redis Module• Benchmark, debug, fine-tune and troubleshoot various issues in RedisIn DetailRedis is considered the world's most popular key-value store database. Its versatility and the wide variety of use cases it enables have made it a popular choice of database for many enterprises. Based on the latest version of Redis, this book provides both step-by-step recipes and relevant the background information required to utilize its features to the fullest. It covers everything from a basic understanding of Redis data types to advanced aspects of Redis high availability, clustering, administration, and troubleshooting. This book will be your great companion to master all aspects of Redis.The book starts off by installing and configuring Redis for you to get started with ease. Moving on, all the data types and features of Redis are introduced in detail. Next, you will learn how to develop applications with Redis in Java, Python, and the Spring Boot web framework. You will also learn replication tasks, which will help you to troubleshoot replication issues. Furthermore, you will learn the steps that need to be undertaken to ensure high availability on your cluster and during production deployment. Toward the end of the book, you will learn the topmost tasks that will help you to troubleshoot your ecosystem efficiently, along with extending Redis by using different modules.Style and approachThis book is a rich collection of recipes that will come in handy when you are working with Redis. It addresses your common and not-so-common pain points, so this is a book of Redis that you must have on the shelf.
Frequently asked questions
Information
Setting Up High Availability and Cluster
- Setting up Sentinel
- Testing Sentinel
- Administrating Sentinel
- Setting up Redis Cluster
- Testing Redis Cluster
- Administrating Redis Cluster
Introduction
Setting up Sentinel
Getting ready…
Role | IP address | Port |
Master | 192.168.0.31 | 6379 |
Slave-1 | 192.168.0.32 | 6379 |
Slave-2 | 192.168.0.33 | 6379 |
Sentinel-1 | 192.168.0.31 | 26379 |
Sentinal-2 | 192.168.0.32 | 26379 |
Sentinel-3 | 192.168.0.33 | 26379 |
bind 127.0.0.1 192.168.0.31
How to do it...
- Prepare a configuration file, sentinel.conf, on each host. You can get a sample copy from the source code. Make sure the configuration file is writable by the user who runs the Sentinel process:
port 26379 dir /tmp sentinel monitor mymaster 192.168.0.31 6379 2 sentinel down-after-milliseconds mymaster 30000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 180000
- Start Sentinel processes on three hosts:
[email protected]:~$bin/redis-server conf/sentinel.conf --sentinel [email protected]:~$bin/redis-server conf/sentinel.conf --sentinel [email protected]:~$bin/redis-server conf/sentinel.conf --sentinel
- Examine the logs on Sentinel-1:
21758:X 29 Oct 22:31:51.001 # Sentinel ID is 3ef95f7fd6420bfe22e38bfded1399382a63ce5b 21758:X 29 Oct 22:31:51.001 # +monitor master mymaster 192.168.0.31 6379 quorum 2 21758:X 29 Oct 22:31:51.001 * +slave slave 192.168.0.32:6379 192.168.0.32 6379 @ mymaster 192.168.0.31 6379 21758:X 29 Oct 22:31:51.003 * +slave slave 192.168.0.33:6379 192.168.0.33 6379 @ mymaster 192.168.0.31 6379 21758:X 29 Oct 22:31:52.021 * +sentinel sentinel d24979c27871eafa62e797d1c8e51acc99bbda72 192.168.0.32 26379 @ mymaster 192.168.0.31 6379 21758:X 29 Oct 22:32:17.241 * +sentinel sentinel a276b044b26100570bb1a4d83d5b3f9d66729f64 192.168.0.33 26379 @ mymaster 192.168.0.31 6379
- Connect to Sentinel-1 using redis-cli and execute the INFO SENTINEL command. Please don't forget to specify the port, 26379:
[email protected]:~$ bin/redis-cli -p 26379 127.0.0.1:26379> INFO SENTINEL # Sentinel sentinel_masters:1 sentinel_tilt:0 sentinel_running_scripts:0 sentinel_scripts_queue_length:0 sentinel_simulate_failure_flags:0 master0:name=mymaster,status=ok,address=192.168.0.31:6379,slaves=2,sentinels=3
- Examine the content of sentinel.conf on Sentinel-1:
[email protected]:~$ cat conf/sentinel.c...