redisable 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redisable/connection.rb +12 -2
- data/lib/redisable/version.rb +1 -1
- data/spec/connection_spec.rb +32 -9
- metadata +15 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b57212d5aeb166fba9f21be08b1ebe7dfc933c22
|
4
|
+
data.tar.gz: dc7696ee7a7793d7edb52a7c8d7be5ebebe2488b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5cf2c005bfbfb69921b083ba6a03f658d0c9e9dfbf0f66752c2018bf376f63e0874ce6c901547224aee6f9e7500460c36c9d552d6fce0e6b45ec0256b343b20
|
7
|
+
data.tar.gz: 322bf121d7ec72c32966623726611e69ddb7f2c22bbec37e6f773c3d02ffde2469322cab59d62d9a45c788c72268bd74e0a1cb9022f16337ee6d3602188f26ca
|
data/lib/redisable/connection.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
require 'redis/distributed'
|
3
|
+
|
2
4
|
module Redisable
|
3
5
|
module Connection
|
4
6
|
def self.conn(server)
|
@@ -6,8 +8,16 @@ module Redisable
|
|
6
8
|
@pool[server] ||=
|
7
9
|
begin
|
8
10
|
conf = Redisable::Config.conf(server)
|
9
|
-
redis =
|
10
|
-
|
11
|
+
redis = nil
|
12
|
+
if conf.is_a?(Array)
|
13
|
+
redis = ::Redis::Distributed.new(conf)
|
14
|
+
redis.nodes.each do |node|
|
15
|
+
raise "Redis server[#{node.id}] is down!" unless reachable?(node)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
redis = ::Redis.new(conf)
|
19
|
+
raise "Redis server[#{redis.id}] is down!" unless reachable?(redis)
|
20
|
+
end
|
11
21
|
redis
|
12
22
|
end
|
13
23
|
end
|
data/lib/redisable/version.rb
CHANGED
data/spec/connection_spec.rb
CHANGED
@@ -11,25 +11,48 @@ describe Redisable::Connection do
|
|
11
11
|
}
|
12
12
|
}
|
13
13
|
describe ".conn" do
|
14
|
+
before do
|
15
|
+
Redisable::Config.stub(:conf) { conf }
|
16
|
+
Redis.any_instance.stub(:ping) { "PONG" }
|
17
|
+
end
|
18
|
+
after do
|
19
|
+
Redisable::Connection.instance_variable_set("@pool", {})
|
20
|
+
end
|
21
|
+
subject { Redisable::Connection.conn(server) }
|
14
22
|
context "in access ':application' first time" do
|
15
23
|
it "create connection" do
|
16
|
-
|
17
|
-
Redis.any_instance.stub(:ping) { "PONG" }
|
18
|
-
Redisable::Connection.conn(server)
|
24
|
+
subject
|
19
25
|
Redisable::Connection.instance_variable_get("@pool").size.should == 1
|
20
26
|
end
|
21
|
-
|
22
|
-
|
27
|
+
end
|
28
|
+
context "sharding conf" do
|
29
|
+
let(:conf) {
|
30
|
+
[
|
31
|
+
{
|
32
|
+
host: "localhost",
|
33
|
+
port: "6379",
|
34
|
+
db: "1",
|
35
|
+
},
|
36
|
+
{
|
37
|
+
host: "localhost",
|
38
|
+
port: "6379",
|
39
|
+
db: "2",
|
40
|
+
},
|
41
|
+
]
|
42
|
+
}
|
43
|
+
it "create sharding connection" do
|
44
|
+
expect(subject).to be_a(Redis::Distributed)
|
23
45
|
end
|
24
46
|
end
|
25
47
|
context "in request timeout" do
|
26
|
-
|
48
|
+
before do
|
27
49
|
Redisable::Config.stub(:conf) { conf }
|
28
50
|
Redis.any_instance.stub(:ping) { "" }
|
29
|
-
|
30
|
-
|
31
|
-
}.to raise_error(RuntimeError)
|
51
|
+
end
|
52
|
+
it "raise RuntimeError" do
|
53
|
+
expect {subject}.to raise_error(RuntimeError)
|
32
54
|
end
|
33
55
|
end
|
34
56
|
end
|
57
|
+
|
35
58
|
end
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redisable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoppi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Thin wrapper library for Redis, enable any Ruby class to access Redis.
|
@@ -73,8 +73,8 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
78
|
- Gemfile
|
79
79
|
- LICENSE.txt
|
80
80
|
- README.md
|
@@ -100,17 +100,17 @@ require_paths:
|
|
100
100
|
- lib
|
101
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
|
-
- -
|
103
|
+
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.0
|
113
|
+
rubygems_version: 2.2.0
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Thin wrapper library for Redis.
|
@@ -120,4 +120,3 @@ test_files:
|
|
120
120
|
- spec/key_spec.rb
|
121
121
|
- spec/redisable_spec.rb
|
122
122
|
- spec/spec_helper.rb
|
123
|
-
has_rdoc:
|