# Redis::Sentinel (Deprecated)
The [redis](https://github.com/redis/redis-rb) gem supports sentinel
from version 3.2, redis-sentinel is not necessary if you are using Redis 2.8.x or later.
Another redis automatic master/slave failover solution for ruby by
using built-in redis sentinel.
It subscribes message with channel "+switch-master", when message
received, it will disconnect current connection and connect to new
master server.
## Installation
Add this line to your application's Gemfile:
gem 'redis-sentinel'
If you are using redis-server less than 2.6.10, please use
redis-sentinel 1.3.0
gem 'redis-sentinel', '~> 1.3.0'
And then execute:
$ bundle
Or install it yourself as:
$ gem install redis-sentinel
## Usage
Specify the sentinel servers and master name
Redis.new(master_name: "master1", sentinels: [{host: "localhost", port: 26379}, {host: "localhost", port: 26380}])
Sentinels can also be specified using a URI. This URI syntax is required when using Rails.config.cache_store:
config.cache_store = :redis_store, { master_name: "master1",
sentinels: ['sentinel://localhost:26379', 'sentinel://localhost:26380'] }
After doing the above, you might still see `#<Redis client v3.1.0 for redis://localhost:6379/0>`.
This is fine because redis-sentinel will only try to connect when it is actually required.
However, if none of the sentinel servers can be reached, a Redis::CannotConnectError will be thrown.
There are two additional options:
1. `:failover_reconnect_timeout` (seconds) will block for that long when
redis is unreachable to give failover enough time to take place. Does
not wait if not given, or time given is 0.
2. `:failover_reconnect_wait` (seconds) how long to sleep after each
failed reconnect during a failover event. Defaults to 0.1s.
## Slaves clients
If you need it, you can get an array of Redis clients, each pointing to one of the slaves:
client = Redis.new(master_name: "master1", sentinels: [{host: "localhost", port: 26379}, {host: "localhost", port: 26380}])
client.slaves
# => [#<Redis client v3.0.7 for redis://127.0.0.1:6380/0>, #<Redis client v3.0.7 for redis://127.0.0.1:6381/0>]
You can also get an array of all the clients (master + slaves):
client = Redis.new(master_name: "master1", sentinels: [{host: "localhost", port: 26379}, {host: "localhost", port: 26380}])
client.all_clients
# => [#<Redis client v3.0.7 for redis://127.0.0.1:6379/0>, #<Redis client v3.0.7 for redis://127.0.0.1:6380/0>, #<Redis client v3.0.7 for redis://127.0.0.1:6381/0>]
## Example
Start redis master server, listen on port 16379
```
$ redis-server example/redis-master.conf
```
Start redis slave server, listen on port 16380
```
$ redis-server example/redis-slave.conf
```
Start 2 sentinel servers
```
$ redis-server example/redis-sentinel1.conf --sentinel
$ redis-server example/redis-sentinel2.conf --sentinel
$ redis-server example/redis-sentinel3.conf --sentinel
```
Run example/test.rb, which will query value of key "foo" every second.
```
$ bundle exec ruby example/test.rb
```
You will see output "bar" every second. Let's try the failover process.
1. Stop redis master server.
2. You will see error message output.
3. Redis sentinel promote redis slave server to master. During this time
you will see errors instead of "bar" while the failover is happening.
4. Then you will see correct "bar" output every second again.
## Example of Failover Timeout
Run the same example code above but run:
```
$ bundle exec ruby example/test_wait_for_failover.rb
```
You will see the stream of "bar" will stop while failover is taking
place and will resume once it has completed, provided that failover
takes less than 30 seconds.
## Authors and Contributors
[https://github.com/flyerhzm/redis-sentinel/graphs/contributors](https://github.com/flyerhzm/redis-sentinel/graphs/contributors)
Please fork and contribute, any help in making this project better is appreciated!
This project is a member of the [OSS Manifesto](http://ossmanifesto.org/).
## Copyright
Copyright @ 2012 - 2015 Richard Huang. See [MIT-LICENSE](https://github.com/flyerhzm/redis-sentinel/blob/master/MIT-LICENSE) for details
徐浪老师
- 粉丝: 8525
- 资源: 1万+
最新资源
- 基于多边形逼近与仿射不变量的部分遮挡物体识别算法
- matlab 滤波器设计,基于matlab的模拟滤波器和数字滤波器设计,其中数字滤波器包扩IIR和FIR的低通、高通、带通、带阻四大类型,模拟滤波器包括巴特沃斯(Butterworth)和切比雪夫(C
- 基于PyCharm开发实现串口与MQTT客户端互相转发工具的python源码
- C2000,28335Matlab Simulink代码生成技术,处理器在环,里面有电力电子常用的GPIO,PWM,ADC,DMA,定时器中断等各种电力电子工程师常用的模块儿,只需要有想法剩下的全部自
- 基于几何距离非迭代最小二乘法椭圆拟合方法及其应用
- 逻辑漏洞ppt总结文件
- 电子PCB板龙门铣自动化生产线sw17可编辑全套技术资料100%好用.zip
- 椭圆拟合中误差变量回归的双重最优方法研究与应用
- 1735975657158015_2648_104187696.html
- 双机并联同步发电机仿真模型 并联同步发电机 1.两台VSG并联,开始各自带负载10KW,在0.3秒的时候加入公共负载10KW,稳定后两台VSG可以均分公共负载的功率 2.输出的三相电压电流波形THD<
- 解码《黑神话:悟空》背后的计算机技术
- comsol锂枝晶模型 Comsol 锂枝晶生长模型,锂枝晶生长,锂离子浓度分布,电势分布 此链接是无序生长随机形核
- 二维码生成与解析工具,给二维码进行加密解密
- 该模型采用无差拿电流预测控制代替传统电流环的PI控制器,并采用模型参自适应对电机参数进行辨识
- 200smart 电子洁净厂房净化空调串级 P ID 自控程序 串级 PID 控制 自写双向 PID 子程序 自写露点与焓值计算子程序 控制精度:温度+-1 度,湿度+-5%
- 电梯厅门板喷粉机器人自动上下件工作站sw19可编辑全套技术资料100%好用.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈