rails_kvs_driver 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/rails_kvs_driver/version.rb +1 -1
- data/lib/rails_kvs_driver.rb +17 -1
- data/spec/rails_kvs_driver_spec.rb +28 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43aaa6cb1c1eda29e5fde51a68910efef0130eab
|
4
|
+
data.tar.gz: f4b8ad4279aeb5bb9fcc4932a7f19fc0f86397ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e067da7e256b8ed8c2e10e150a544d982543c44fb13e42aecd6d9b40f7404ea6dcc830152f4f8aa1e641118fbffb5d01a86491e250623415c410495f227b2a77
|
7
|
+
data.tar.gz: 7b4fa836600e0f9a8134c2cd7b2a6443038786ad87139bb8de6af8cd9a3784e4f6015af0552bf02b5e1b54cc05df602378732565fe329a16cc1f451fa5b236b0
|
data/README.md
CHANGED
data/lib/rails_kvs_driver.rb
CHANGED
@@ -133,7 +133,7 @@ module RailsKvsDriver
|
|
133
133
|
# @param key [String] key of sorted set.
|
134
134
|
# @param start [Integer] start index
|
135
135
|
# @param stop [Integer] stop index
|
136
|
-
# @param reverse [Boolean] order by desc
|
136
|
+
# @param reverse [Boolean] order by desc.
|
137
137
|
# @return [Array<String, Float>>] array of the member and score.
|
138
138
|
# @abstract get array of sorted set.
|
139
139
|
def sorted_set(key, start=0, stop=-1, reverse=false)
|
@@ -149,6 +149,22 @@ module RailsKvsDriver
|
|
149
149
|
raise NoMethodError
|
150
150
|
end
|
151
151
|
|
152
|
+
# execute the block of code for each member of sorted set.
|
153
|
+
# @param key [String] key of sorted set.
|
154
|
+
# @param reverse [Boolean] order by desc.
|
155
|
+
# @param limit [Integer] limit number to acquire at a time.
|
156
|
+
# @param &block [{|member, score, position| }] each the block of code for each member of sorted set.
|
157
|
+
def each_sorted_set(key, reverse=false, limit=1000)
|
158
|
+
member_count = count_sorted_set_member(key)
|
159
|
+
member_position = 0
|
160
|
+
|
161
|
+
while member_position < member_count
|
162
|
+
sorted_set(key, member_position, member_position + (limit-1), reverse).each do |data|
|
163
|
+
yield data[0], data[1], member_position
|
164
|
+
member_position += 1
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
152
168
|
|
153
169
|
# connect kvs and exec block.
|
154
170
|
# This function pools the connecting driver.
|
@@ -151,5 +151,33 @@ describe RailsKvsDriver do
|
|
151
151
|
expect(MockDriver::DriverConnectionPool['MockDriver2'][0].has_key? :pool).to be_true
|
152
152
|
end
|
153
153
|
|
154
|
+
it 'call each_sorted_set' do
|
155
|
+
class MockDriverEachTest < MockDriver
|
156
|
+
def sorted_set(key, start, stop, reverse)
|
157
|
+
count = 0
|
158
|
+
result = Array.new
|
159
|
+
(start .. stop).each{ |num|
|
160
|
+
result.push ["example#{num}", count]
|
161
|
+
count += 1
|
162
|
+
}
|
163
|
+
return result
|
164
|
+
end
|
165
|
+
def count_sorted_set_member(*args)
|
166
|
+
100
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
MockDriverEachTest.session(@driver_config) do |instance|
|
171
|
+
count = 0
|
172
|
+
expect{
|
173
|
+
instance.each_sorted_set('test',false, 10) do |member, score, position|
|
174
|
+
expect(member).to eq("example#{count}")
|
175
|
+
expect(score).to eq(count%10)
|
176
|
+
expect(position).to eq(count)
|
177
|
+
count += 1
|
178
|
+
end
|
179
|
+
}.to change{count}.by(100)
|
180
|
+
end
|
181
|
+
end
|
154
182
|
end
|
155
183
|
end
|