redic-sentinels 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +68 -0
- data/config/redis-master.conf +540 -0
- data/config/redis-sentinel-1.conf +10 -0
- data/config/redis-sentinel-2.conf +10 -0
- data/config/redis-sentinel-3.conf +10 -0
- data/config/redis-slave.conf +541 -0
- data/lib/redic/sentinels/version.rb +5 -0
- data/lib/redic/sentinels.rb +76 -0
- data/lib/redic-sentinels.rb +1 -0
- data/redic-sentinels.gemspec +37 -0
- data/spec/minitest_helper.rb +7 -0
- data/spec/sentinels_spec.rb +110 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54d236a916888c25a0413816ec6e2c649100db9c
|
4
|
+
data.tar.gz: 62b9e67398198edc52ce30b6956692eeb7f0c7da
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: adb8e3aa13617616c2c3979b41ec105956b0473c3d0c16acdc5537b2a36fd5f31c22aef9ad68c8bc68899820bcf3e04ccd2224dd7d859035a7e476e3484ce651
|
7
|
+
data.tar.gz: 3c5b8d27b12d9585c2a11b2d8c7e924ed5260102c6ebf66b063a40718cae546d06a2234e577d492c82463335c1081243eb1bbad52cdfc62ea3739a484f7faac9
|
data/.coveralls.yml
ADDED
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
redic-sentinels
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Gabriel Naiman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Redic::Sentinels
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/redic-sentinels)
|
4
|
+
[](https://travis-ci.org/gabynaiman/redic-sentinels)
|
5
|
+
[](https://coveralls.io/r/gabynaiman/redic-sentinels?branch=master)
|
6
|
+
[](https://codeclimate.com/github/gabynaiman/redic-sentinels)
|
7
|
+
[](https://gemnasium.com/gabynaiman/redic-sentinels)
|
8
|
+
|
9
|
+
Redic::Sentinels is a wrapper for the Redis client that fetches configuration details from sentinels.
|
10
|
+
|
11
|
+
Based on [soveran/redisent](https://github.com/soveran/redisent)
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'redic-sentinels'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install redic-sentinels
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
sentinels = [
|
33
|
+
'localhost:26379',
|
34
|
+
'localhost:26380',
|
35
|
+
'localhost:26381'
|
36
|
+
]
|
37
|
+
|
38
|
+
redis = Redic::Sentinels.new sentinels: sentinels,
|
39
|
+
master_name: 'mymaster',
|
40
|
+
db: 1, # optional (default: 0)
|
41
|
+
password: 'pass' # optional
|
42
|
+
|
43
|
+
redis.call 'PING' # => 'PONG'
|
44
|
+
```
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gabynaiman/redic-sentinels.
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
53
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new(:spec) do |t|
|
5
|
+
t.libs << 'spec'
|
6
|
+
t.pattern = 'spec/**/*_spec.rb'
|
7
|
+
t.verbose = false
|
8
|
+
t.warning = false
|
9
|
+
t.loader = nil if ENV['TEST']
|
10
|
+
ENV['TEST'], ENV['LINE'] = ENV['TEST'].split(':') if ENV['TEST'] && !ENV['LINE']
|
11
|
+
t.options = ''
|
12
|
+
t.options << "--name=/#{ENV['NAME']}/ " if ENV['NAME']
|
13
|
+
t.options << "-l #{ENV['LINE']} " if ENV['LINE'] && ENV['TEST']
|
14
|
+
end
|
15
|
+
|
16
|
+
task :console do
|
17
|
+
require 'pry'
|
18
|
+
require 'redic-sentinels'
|
19
|
+
ARGV.clear
|
20
|
+
Pry.start
|
21
|
+
end
|
22
|
+
|
23
|
+
task default: :spec
|
24
|
+
|
25
|
+
namespace :redis do
|
26
|
+
|
27
|
+
REDIS_CONFIGURATIONS = Dir['config/*.conf'].map { |f| File.basename(f,'.conf')[6..-1] }
|
28
|
+
|
29
|
+
def start_redis(config)
|
30
|
+
args = config.start_with?('sentinel') ? '--sentinel' : ''
|
31
|
+
sh "sudo redis-server config/redis-#{config}.conf #{args}"
|
32
|
+
rescue => ex
|
33
|
+
puts "Cant start #{config}: #{ex.message}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def stop_redis(config)
|
37
|
+
pidfile = File.expand_path "/tmp/redic-sentinels-#{config}.pid"
|
38
|
+
pid = File.read pidfile
|
39
|
+
sh "sudo kill -s TERM #{pid}"
|
40
|
+
rescue => ex
|
41
|
+
puts "Cant stop #{config}: #{ex.message}"
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Start Redis Server for specific configuration (CONFIG=master)'
|
45
|
+
task :start do
|
46
|
+
start_redis ENV.fetch('CONFIG').downcase
|
47
|
+
end
|
48
|
+
|
49
|
+
namespace :start do
|
50
|
+
desc 'Start Redis Server for all configurations'
|
51
|
+
task :all do
|
52
|
+
REDIS_CONFIGURATIONS.each { |c| start_redis c }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
desc 'Stop Redis Server for specific configuration (CONFIG=master)'
|
57
|
+
task :stop do
|
58
|
+
stop_redis ENV.fetch('CONFIG').downcase
|
59
|
+
end
|
60
|
+
|
61
|
+
namespace :stop do
|
62
|
+
desc 'Stop Redis Server for all configurations'
|
63
|
+
task :all do
|
64
|
+
REDIS_CONFIGURATIONS.each { |c| stop_redis c }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|