GithubHelp home page GithubHelp logo

isabella232 / redis-sentinel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zendesk/redis-sentinel

0.0 0.0 0.0 184 KB

another redis automatic master/slave failover solution for ruby by using built-in redis sentinel

Home Page: https://github.com/flyerhzm/redis-sentinel

License: MIT License

Ruby 100.00%

redis-sentinel's Introduction

Redis::Sentinel

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}])

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.

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

Please fork and contribute, any help in making this project better is appreciated!

This project is a member of the OSS Manifesto.

Copyright

Copyright @ 2012 - 2013 Richard Huang. See MIT-LICENSE for details

redis-sentinel's People

Contributors

dplummer avatar edsinclair avatar flyerhzm avatar mikegee avatar nick-desteffen avatar rbroemeling avatar royaltm avatar zanker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.