README.md in rails_failover-0.4.0 vs README.md in rails_failover-0.5.0
- old
+ new
@@ -1,15 +1,18 @@
# RailsFailover
-* Automatic failover and recovery for simple master-replica Redis setup
+Automatic failover and recovery for primary/replica setup for:
+1. Redis
+1. ActiveRecord (PostgreSQL/MySQL)
+
## Installation
Add this line to your application's Gemfile:
```ruby
-gem 'rails_failover'
+gem 'rails_failover', require: false
```
And then execute:
$ bundle install
@@ -34,25 +37,62 @@
replica_port: <replica db server port>
```
The gem will automatically create an `ActiveRecord::ConnectionAdapters::ConnectionHandler` with the `ActiveRecord::Base.reading_role` as the `handler_key`.
+#### Failover/Fallback Hooks
+
+```
+RailsFailover::ActiveRecord.on_failover do
+ # Enable readonly mode
+end
+
+RailsFailover::ActiveRecord.on_fallback do
+ # Disable readonly mode
+end
+```
+
+#### Multiple connection handlers
+
+Note: This API is unstable and is likely to changes when Rails 6.1 is released with sharding support.
+
+```
+# config/database.yml
+
+production:
+ primary:
+ host: <primary db server host>
+ port: <primary db server port>
+ replica_host: <replica db server host>
+ replica_port: <replica db server port>
+ second_database_writing:
+ host: <primary db server host>
+ port: <primary db server port>
+ replica_host: <replica db server host>
+ replica_port: <replica db server port>
+
+# In your ActiveRecord base model or model.
+
+connects_to database: { writing: :primary, second_database_writing: :second_database_writing
+```
+
### Redis
+Add `require 'rails_failover/redis'` before creating a `Redis` instance.
+
```
Redis.new(host: "127.0.0.1", port: 6379, replica_host: "127.0.0.1", replica_port: 6380, connector: RailsFailover::Redis::Connector))
```
-Callbacks can be registered when the master connection is down and when it is up.
+Callbacks can be registered when the primary connection is down and when it is up.
-
```
-RailsFailover::Redis.register_master_up_callback do
+RailsFailover::Redis.on_failover_callback do
# Switch site to read-only mode
end
-RailsFailover::Redis.register_master_down_callback do
+RailsFailover::Redis.on_fallback_callback do
# Switch site out of read-only mode
end
```
## Development
@@ -76,10 +116,9 @@
`bin/rspec redis`
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/discourse/rails_failover. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/discourse/rails_failover/blob/master/CODE_OF_CONDUCT.md).
-
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).