redisent 0.0.1
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.
- data/LICENSE +19 -0
- data/README +44 -0
- data/lib/redisent.rb +23 -0
- data/test/redisent_test.rb +38 -0
- metadata +73 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Michel Martens
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
redisent
|
2
|
+
====
|
3
|
+
|
4
|
+
Sentinel aware Redis client.
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Redisent is a wrapper for the Redis client that fetches configuration
|
10
|
+
details from sentinels.
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
Instead of passing a Redis URL, you have to pass an array with the
|
15
|
+
URLs of your Redis sentinels as the first parameter, then the name
|
16
|
+
of your master server (as defined in the sentinels configuration) as
|
17
|
+
the second parameter, and finally a hash of options to be used when
|
18
|
+
connecting to the master.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
# List of sentinels.
|
22
|
+
sentinels = ["redis://localhost:27379/",
|
23
|
+
"redis://localhost:27380/",
|
24
|
+
"redis://localhost:27381/"]
|
25
|
+
|
26
|
+
# Master server name as defined in sentinel.conf.
|
27
|
+
master = "server-1"
|
28
|
+
|
29
|
+
# Additional options for the master server.
|
30
|
+
options = { :timeout => 5, :password => "abcd" }
|
31
|
+
|
32
|
+
redis = Redisent.new(sentinels, master, options)
|
33
|
+
```
|
34
|
+
|
35
|
+
If the sentinels can't be reached, or if there is no master available,
|
36
|
+
you will get the exception `Redis::CannotConnectError`.
|
37
|
+
|
38
|
+
## Installation
|
39
|
+
|
40
|
+
You can install it using rubygems:
|
41
|
+
|
42
|
+
```
|
43
|
+
$ gem install redisent
|
44
|
+
```
|
data/lib/redisent.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "redis"
|
2
|
+
|
3
|
+
module Redisent
|
4
|
+
def self.new(sentinels, master, options = {})
|
5
|
+
sentinels.each do |sentinel|
|
6
|
+
begin
|
7
|
+
master = find_master(sentinel, master, options)
|
8
|
+
return master if master
|
9
|
+
rescue Redis::CannotConnectError
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
raise Redis::CannotConnectError
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find_master(sentinel, master, options)
|
17
|
+
redis = Redis.new(url: sentinel)
|
18
|
+
|
19
|
+
host, port = redis.sentinel("get-master-addr-by-name", master)
|
20
|
+
|
21
|
+
Redis.new(options.merge(:host => host, :port => port))
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path("../lib/redisent", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
test "basics" do |redis|
|
4
|
+
redis = Redisent.new(
|
5
|
+
["redis://localhost:27378/",
|
6
|
+
"redis://localhost:27379/",
|
7
|
+
"redis://localhost:27380/",
|
8
|
+
"redis://localhost:27381/"],
|
9
|
+
"server-1", :timeout => 5)
|
10
|
+
|
11
|
+
redis.set("foo", 1)
|
12
|
+
|
13
|
+
assert_equal "1", redis.get("foo")
|
14
|
+
assert_equal "6379", redis.info["tcp_port"]
|
15
|
+
assert_equal 5.0, redis.client.timeout
|
16
|
+
end
|
17
|
+
|
18
|
+
test "no available sentinel" do
|
19
|
+
assert_raise Redis::CannotConnectError do
|
20
|
+
redis = Redisent.new(
|
21
|
+
["redis://localhost:27478/",
|
22
|
+
"redis://localhost:27479/",
|
23
|
+
"redis://localhost:27480/",
|
24
|
+
"redis://localhost:27481/"],
|
25
|
+
"server-1")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
test "no available master" do
|
30
|
+
assert_raise Redis::CannotConnectError do
|
31
|
+
redis = Redisent.new(
|
32
|
+
["redis://localhost:27478/",
|
33
|
+
"redis://localhost:27479/",
|
34
|
+
"redis://localhost:27480/",
|
35
|
+
"redis://localhost:27481/"],
|
36
|
+
"server-2")
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redisent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Michel Martens
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redis
|
16
|
+
requirement: &2155997400 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2155997400
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: cutest
|
27
|
+
requirement: &2155996720 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2155996720
|
36
|
+
description: Redisent is a wrapper for the Redis client that fetches configuration
|
37
|
+
details from sentinels.
|
38
|
+
email:
|
39
|
+
- michel@soveran.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- LICENSE
|
45
|
+
- README
|
46
|
+
- lib/redisent.rb
|
47
|
+
- test/redisent_test.rb
|
48
|
+
homepage: https://github.com/soveran/redisent
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.11
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Sentinel aware Redis client.
|
73
|
+
test_files: []
|