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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9c2d6bc0f0efa423e900af03e85f7f483a1c130
4
- data.tar.gz: eef288a528f469bbb1b9d8a13ab6738ad6a1657a
3
+ metadata.gz: 43aaa6cb1c1eda29e5fde51a68910efef0130eab
4
+ data.tar.gz: f4b8ad4279aeb5bb9fcc4932a7f19fc0f86397ca
5
5
  SHA512:
6
- metadata.gz: 0a8ac3db947ca01228bd56851dbafc146feb00f4e3a9f8d6c6e41107b7dec4c306a099aba15a52b2dc6840d1e57e4b79a0ca801212d6d564e8b1e5687578e732
7
- data.tar.gz: 2b710cfc50e54ba49492be948f85797a04d7789fcca0600626b9e1e695dfbe5954a28184982f09f96a0256de3928116b3dc3850c7705e71dca640486a71cbb5b
6
+ metadata.gz: e067da7e256b8ed8c2e10e150a544d982543c44fb13e42aecd6d9b40f7404ea6dcc830152f4f8aa1e641118fbffb5d01a86491e250623415c410495f227b2a77
7
+ data.tar.gz: 7b4fa836600e0f9a8134c2cd7b2a6443038786ad87139bb8de6af8cd9a3784e4f6015af0552bf02b5e1b54cc05df602378732565fe329a16cc1f451fa5b236b0
data/README.md CHANGED
@@ -16,6 +16,10 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install rails_kvs_driver
18
18
 
19
+ ## Implementation
20
+
21
+ * [rails_kvs_driver-redis_driver](https://github.com/alfa-jpn/rails_kvs_driver-redis_driver)
22
+
19
23
  ## Usage
20
24
 
21
25
  comming soon.
@@ -1,3 +1,3 @@
1
1
  module RailsKvsDriver
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_kvs_driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - alfa-jpn