redqueen 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/Guardfile +22 -0
- data/Rakefile +6 -0
- data/lib/redqueen/client.rb +28 -0
- data/lib/redqueen/version.rb +1 -1
- data/lib/redqueen.rb +38 -3
- data/redqueen.gemspec +9 -0
- data/spec/lib/redqueen/client_spec.rb +22 -0
- data/spec/lib/redqueen_spec.rb +10 -0
- data/spec/spec_helper.rb +20 -0
- metadata +124 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56e7bc5ceb4c500d7d86dc4bc4f23593947e62d6
|
4
|
+
data.tar.gz: 316ca65d70124e97f4eb33a71b3bbd567132a73e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c34a81439e6f88b5cbfce20a9cdec50177603fbeae9dae6414be1063e0e7048fe5cbc15e2847c5f7ce42728389ae2a5b2b18153958afe155de526ebe6e1e037d
|
7
|
+
data.tar.gz: de2c1d56e339deb3e4b75aac61456b20c18621c63190cdb6557532fc68cc6f12dba31c131f645c8c11093ddae0781fdf8506b54961c16bfe8f234a0106e2d06b
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Guardfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :bundler do
|
5
|
+
watch('Gemfile')
|
6
|
+
# Uncomment next line if your Gemfile contains the `gemspec' command.
|
7
|
+
watch(/^.+\.gemspec/)
|
8
|
+
end
|
9
|
+
|
10
|
+
guard :rspec do
|
11
|
+
watch(%r{^spec/.+_spec\.rb$})
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
13
|
+
watch('spec/spec_helper.rb') { "spec" }
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
# # Add files and commands to this file, like the example:
|
18
|
+
# # watch(%r{file/path}) { `command(s)` }
|
19
|
+
# #
|
20
|
+
# guard 'shell' do
|
21
|
+
# watch(/(.*).txt/) {|m| `tail #{m[0]}` }
|
22
|
+
# end
|
data/Rakefile
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
module RedQueen
|
2
|
+
class Client
|
3
|
+
def initialize prefix, client
|
4
|
+
@prefix = prefix
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
def get key
|
9
|
+
unpack @client.get prefix(key)
|
10
|
+
end
|
11
|
+
|
12
|
+
def set key, value
|
13
|
+
@client.set prefix(key), value.to_msgpack
|
14
|
+
end
|
15
|
+
|
16
|
+
def select index
|
17
|
+
@client.select index
|
18
|
+
end
|
19
|
+
|
20
|
+
def prefix key
|
21
|
+
[@prefix, key].join(':')
|
22
|
+
end
|
23
|
+
|
24
|
+
def unpack item
|
25
|
+
MessagePack.unpack item
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/redqueen/version.rb
CHANGED
data/lib/redqueen.rb
CHANGED
@@ -1,5 +1,40 @@
|
|
1
|
-
require
|
1
|
+
require 'redqueen/version'
|
2
|
+
require 'redqueen/client'
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
require 'active_support/all'
|
5
|
+
|
6
|
+
|
7
|
+
module RedQueen
|
8
|
+
class Queen
|
9
|
+
attr_reader :clients
|
10
|
+
delegate :get, :set, to: :client
|
11
|
+
|
12
|
+
def initialize servers
|
13
|
+
@clients = [servers].reject{|s| s.blank?}.flatten.map do |server|
|
14
|
+
parts = server.split(':')
|
15
|
+
client = Redis.new host: (parts[0] || 'localhost'), port: (parts[1].to_i || 6379 rescue 6379)
|
16
|
+
RedQueen::Client.new prefix, client
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def select index
|
21
|
+
@clients.map{|c| c.select index}
|
22
|
+
end
|
23
|
+
|
24
|
+
def client
|
25
|
+
@clients.sample
|
26
|
+
end
|
27
|
+
|
28
|
+
def prefix
|
29
|
+
[app_name, app_env]
|
30
|
+
end
|
31
|
+
|
32
|
+
def app_name
|
33
|
+
::Rails.application.class.name.split('::')[0]
|
34
|
+
end
|
35
|
+
|
36
|
+
def app_env
|
37
|
+
::Rails.env
|
38
|
+
end
|
39
|
+
end
|
5
40
|
end
|
data/redqueen.gemspec
CHANGED
@@ -18,6 +18,15 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_runtime_dependency "redis"
|
22
|
+
spec.add_runtime_dependency "active_support"
|
23
|
+
spec.add_runtime_dependency "msgpack"
|
24
|
+
spec.add_runtime_dependency "i18n"
|
25
|
+
|
21
26
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
27
|
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "guard"
|
30
|
+
spec.add_development_dependency "guard-rspec"
|
31
|
+
spec.add_development_dependency "guard-bundler"
|
23
32
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RedQueen::Client do
|
4
|
+
|
5
|
+
it 'should get' do
|
6
|
+
@redis.set 'TestApp:testenv:key1', 'abc'.to_msgpack
|
7
|
+
@redis.set 'TestApp:testenv:mod1:key1', 'def'.to_msgpack
|
8
|
+
@redis.set 'TestApp:testenv:objkey1', {hello: 'world'}.to_msgpack
|
9
|
+
@rq.get('key1').should == 'abc'
|
10
|
+
@rq.get(['mod1','key1']).should == 'def'
|
11
|
+
@rq.get('objkey1').should == {"hello" => "world"}
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should set' do
|
15
|
+
@rq.set 'key1', "abc"
|
16
|
+
MessagePack.unpack(@redis.get('TestApp:testenv:key1')).should == "abc"
|
17
|
+
@rq.set ['mod1','key1'], "def"
|
18
|
+
MessagePack.unpack(@redis.get('TestApp:testenv:mod1:key1')).should == "def"
|
19
|
+
@rq.set ['key2'], {hello: 'world2'}
|
20
|
+
MessagePack.unpack(@redis.get('TestApp:testenv:key2')).should == {"hello" => "world2"}
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RedQueen::Queen do
|
4
|
+
it 'should create as many clients as passed in' do
|
5
|
+
queen = RedQueen::Queen.new ['localhost:6379','localhost:6379','localhost:6379']
|
6
|
+
queen.clients.size.should == 3
|
7
|
+
queen.clients.should include queen.client
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'msgpack'
|
2
|
+
require 'redqueen'
|
3
|
+
require 'redis'
|
4
|
+
|
5
|
+
RSpec.configure do |c|
|
6
|
+
c.before(:each) do
|
7
|
+
Rails ||= double
|
8
|
+
app = double
|
9
|
+
cls = double
|
10
|
+
app.stub(:class).and_return cls
|
11
|
+
cls.stub(:name).and_return "TestApp::Application"
|
12
|
+
Rails.stub(:env).and_return 'testenv'
|
13
|
+
Rails.stub(:application).and_return(app)
|
14
|
+
@redis = Redis.new
|
15
|
+
@rq = RedQueen::Queen.new 'localhost:6379'
|
16
|
+
@redis.select 8
|
17
|
+
@redis.flushdb
|
18
|
+
@rq.select 8
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redqueen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sudhir Jonathan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: active_support
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: msgpack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: i18n
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
13
69
|
- !ruby/object:Gem::Dependency
|
14
70
|
name: bundler
|
15
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +94,62 @@ dependencies:
|
|
38
94
|
- - '>='
|
39
95
|
- !ruby/object:Gem::Version
|
40
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: guard-bundler
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
41
153
|
description: Rails wrapper for Redis
|
42
154
|
email:
|
43
155
|
- sudhir.j@gmail.com
|
@@ -46,13 +158,19 @@ extensions: []
|
|
46
158
|
extra_rdoc_files: []
|
47
159
|
files:
|
48
160
|
- .gitignore
|
161
|
+
- .rspec
|
49
162
|
- Gemfile
|
163
|
+
- Guardfile
|
50
164
|
- LICENSE.txt
|
51
165
|
- README.md
|
52
166
|
- Rakefile
|
53
167
|
- lib/redqueen.rb
|
168
|
+
- lib/redqueen/client.rb
|
54
169
|
- lib/redqueen/version.rb
|
55
170
|
- redqueen.gemspec
|
171
|
+
- spec/lib/redqueen/client_spec.rb
|
172
|
+
- spec/lib/redqueen_spec.rb
|
173
|
+
- spec/spec_helper.rb
|
56
174
|
homepage: ''
|
57
175
|
licenses:
|
58
176
|
- MIT
|
@@ -77,4 +195,7 @@ rubygems_version: 2.1.10
|
|
77
195
|
signing_key:
|
78
196
|
specification_version: 4
|
79
197
|
summary: Rails wrapper for Redis
|
80
|
-
test_files:
|
198
|
+
test_files:
|
199
|
+
- spec/lib/redqueen/client_spec.rb
|
200
|
+
- spec/lib/redqueen_spec.rb
|
201
|
+
- spec/spec_helper.rb
|