rails_kvs_driver-redis_driver 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6bae204bb5e7740f513affc1be5562ea3352ecc0
4
- data.tar.gz: d41b5871f142e939097b696e0adb7077e0b47067
3
+ metadata.gz: 19b774e652fcdea5cf78fc12325f96fc03c7df24
4
+ data.tar.gz: 918da4d9464f9c98a0744d794a97f351150e31cb
5
5
  SHA512:
6
- metadata.gz: 2aa4b20460a75f46d4e8271042dc95ace30755dcc543443b58c68ddf2e44cb3380bb761462103c5e9b92b8406f20eb6406e3370e8be3030a73a724c658ab076a
7
- data.tar.gz: 796f00a3d2e04a3274c1f67eed885b0294dac7383d4133295c134e98dc62b2d6f09d16c458fa96cb8a3b1f419e569c9662a98b5750be6aa8600dc9f226312997
6
+ metadata.gz: a5eaec9a5f0a3997e45bdf447f7b360de964abc3584755e67a11472598ac36b303067ac2e79c5da90d0e95b52c9447cc87100905d710490f92b53b2f1bce8c33
7
+ data.tar.gz: d9dda9ccf5209ed60e8f5188634bc67f25a2270906ca8cd48e4e0ee5cbc24226ad7b333bab81bd9146cce5a13cadaba0b6c9ae737575ce7c3666a02eb4ed0bd9
data/README.md CHANGED
@@ -71,46 +71,62 @@ end
71
71
  RailsKvsDriver::RedisDriver::Driver::session(driver_config) do |redis|
72
72
 
73
73
  # set member to redis.
74
- redis.sorted_sets['animations'] = ['nyarukosan', 10]
75
- redis.sorted_sets['animations'] = ['nonnonbiyori', 5]
76
- redis.sorted_sets['animations'] = ['kiniromosaic', 1]
77
-
74
+ redis.sorted_sets['anime']['nyarukosan'] = 10
75
+ redis.sorted_sets['anime']['nonnonbiyori'] = 10
76
+ redis.sorted_sets['anime']['kiniromosaic'] = 10
77
+
78
+ # or can use this.
79
+ redis.sorted_set['fruit'] = [['apple', 1], [orange, 2]]
80
+
81
+
82
+ # get score of member.
83
+ redis.sorted_sets['anime']['nyarukosan'] # => 10
84
+
85
+
78
86
  # increment score of member.
79
- redis.sorted_sets.increment('animations', 'nyarukosan', 1) # => increment nyarukosan score 10 -> 11
80
- redis.sorted_sets.increment('animations', 'nyarukosan', -1) # => increment nyarukosan score 11 -> 10
81
-
87
+ redis.sorted_sets['anime'].increment('nyarukosan', 1) # => increment nyarukosan score 10 -> 11
88
+ redis.sorted_sets['anime'].increment('nyarukosan', -1) # => increment nyarukosan score 11 -> 10
89
+
90
+
91
+ # execute the block of code for each keys.
92
+ redis.sorted_sets.each do {|key| puts key } # => anime fruit
93
+
82
94
  # execute the block of code for each member of sorted set.
83
- redis.sorted_sets.each_member('animations', true) do |member, score, position|
95
+ redis.sorted_sets['anime'].each(true) do |member, score, position|
84
96
  puts "#{position+1}:#{member} is #{score}pt." # => '1:nyarukosan is 10pt.'
85
97
  # => '2:nonnonbiyori is 5pt.'
86
98
  # => '3:kiniromosaic is 1pt.'
87
99
  end
88
-
100
+
101
+
89
102
  # get all keys
90
- redis.sorted_sets.keys? # => ['animations']
91
-
92
- # execute the block of code for each keys.
93
- redis.sorted_sets.each do |key|
94
- puts key # => animations
95
- end
96
-
97
- # get array of sorted set.
98
- redis.sorted_sets['animation'] # => Array[[member,score],....]
99
-
100
- # get score of member.
101
- redis.sorted_sets['animations', 'nyarukosan'] # => 10
102
-
103
- # count member of sorted set.
104
- redis.sorted_sets.count('animations') # => 3
105
-
103
+ redis.sorted_sets.keys? # => ['anime', 'fruit']
104
+
105
+ # get all members
106
+ redis.sorted_sets['anime'].members? # => nyarukosan nonnonbiyori kiniromosaic
107
+
108
+
109
+ # length of sorted set.
110
+ redis.sorted_sets.length # => 2
111
+
112
+ # length member of sorted set.
113
+ redis.sorted_sets['anime'].length # => 3
114
+
115
+
116
+
117
+ # delete key
118
+ redis.sorted_sets.delete('fruit')
119
+
106
120
  # remove member of sorted set.
107
- redis.sorted_sets.remove('animations', 'nonnonbiyori')
108
-
109
- # check existed sorted set
110
- redis.sorted_sets.has_key?('animations') # => false
111
-
112
- # length sorted set
113
- redis.sorted_set.length # => 0
121
+ redis.sorted_sets['anime'].remove('nonnonbiyori')
122
+
123
+
124
+ # check if key exist.
125
+ redis.sorted_sets.has_key?('fruit') # => false
126
+
127
+ # check if member exist.
128
+ redis.sorted_sets['anime'].has_member?('nyarukosan') # => true
129
+
114
130
 
115
131
  end
116
132
  ```
@@ -14,7 +14,7 @@ module RailsKvsDriver::RedisDriver
14
14
  # get value from kvs.
15
15
  # @param key [String] key.
16
16
  # @return [String] value. when doesn't exist, nil.
17
- def [](key)
17
+ def get(key)
18
18
  @kvs_instance.get(safe_key(key))
19
19
  end
20
20
 
@@ -22,7 +22,7 @@ module RailsKvsDriver::RedisDriver
22
22
  # @param key [String] key.
23
23
  # @param value [String] value.
24
24
  # @return [Boolean] result
25
- def []=(key, value)
25
+ def set(key, value)
26
26
  @kvs_instance.set(safe_key(key), value)
27
27
  end
28
28
 
@@ -1,5 +1,5 @@
1
1
  module RailsKvsDriver
2
2
  module RedisDriver
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "yard"
25
25
 
26
26
  spec.add_dependency "redis"
27
- spec.add_dependency "rails_kvs_driver", "0.1.6"
27
+ spec.add_dependency "rails_kvs_driver", "0.2.1"
28
28
  end
@@ -26,17 +26,17 @@ shared_examples_for 'RailsKvsDriver example' do |driver_class, driver_config|
26
26
  end
27
27
 
28
28
  context 'override methods' do
29
- it 'call []' do
29
+ it 'call get' do
30
30
  driver_class::session(driver_config) do |kvs|
31
- kvs['example'] = 'nico-nico'
32
- expect(kvs['example']).to eq('nico-nico')
33
- expect(kvs['nothing key']).to be_nil
31
+ kvs.set('example', 'nico-nico')
32
+ expect(kvs.get('example')).to eq('nico-nico')
33
+ expect(kvs.get('nothing key')).to be_nil
34
34
  end
35
35
  end
36
36
 
37
- it 'call []=' do
37
+ it 'call set' do
38
38
  driver_class::session(driver_config) do |kvs|
39
- expect{ kvs['example'] = 'nico-nico' }.to change{ kvs.keys.length }.by(1)
39
+ expect{ kvs.set('example', 'nico-nico') }.to change{ kvs.keys.length }.by(1)
40
40
  end
41
41
  end
42
42
 
@@ -156,6 +156,19 @@ shared_examples_for 'RailsKvsDriver example' do |driver_class, driver_config|
156
156
 
157
157
 
158
158
  context 'inheritance methods' do
159
+ it 'call []' do
160
+ driver_class::session(driver_config) do |kvs|
161
+ kvs['example'] = 'nico-nico'
162
+ expect(kvs['example']).to eq('nico-nico')
163
+ expect(kvs['nothing key']).to be_nil
164
+ end
165
+ end
166
+
167
+ it 'call []=' do
168
+ driver_class::session(driver_config) do |kvs|
169
+ expect{ kvs['example'] = 'nico-nico' }.to change{ kvs.keys.length }.by(1)
170
+ end
171
+ end
159
172
 
160
173
  it 'call each' do
161
174
  driver_class::session(driver_config) do |kvs|
@@ -178,120 +191,137 @@ shared_examples_for 'RailsKvsDriver example' do |driver_class, driver_config|
178
191
  end
179
192
 
180
193
  context 'sorted_sets' do
181
-
182
- it 'call []' do
194
+ before(:each) do
183
195
  driver_class::session(driver_config) do |kvs|
184
- kvs.add_sorted_set('example', 'element', 1024)
185
- kvs.add_sorted_set('example', 'element2', 1)
186
-
187
- expect(kvs.sorted_sets['example'].length).to eq(2)
188
- expect(kvs.sorted_sets['example','element']).to eq(1024)
196
+ kvs.add_sorted_set('anime', 'nyaruko', 1024)
197
+ kvs.add_sorted_set('anime', 'haganai', 100)
189
198
  end
190
199
  end
191
200
 
192
- it 'call []=' do
201
+ it 'call []' do
193
202
  driver_class::session(driver_config) do |kvs|
194
- kvs.sorted_sets['example'] = ['element', 1]
195
- kvs.sorted_sets['example'] = ['element2', 1]
196
-
197
- expect(kvs.sorted_sets['example'].length).to eq(2)
203
+ expect(kvs.sorted_sets['anime'].instance_of?(RailsKvsDriver::SortedSets::SortedSet)).to be_true
198
204
  end
199
205
  end
200
206
 
201
- it 'call count' do
207
+ it 'call []=' do
202
208
  driver_class::session(driver_config) do |kvs|
203
- kvs.add_sorted_set('example', 'element', 1)
204
- kvs.add_sorted_set('example', 'element2', 1)
205
209
 
206
- expect(kvs.sorted_sets.count('example')).to eq(2)
210
+ expect{
211
+ kvs.sorted_sets['fruit'] = [['Apple', 1], ['Orange', 2]]
212
+ }.to change{
213
+ kvs.sorted_sets.length
214
+ }.by(1)
215
+
216
+ expect(kvs.sorted_sets['fruit'].length).to eq(2)
207
217
  end
208
218
  end
209
219
 
220
+
210
221
  it 'call delete' do
211
222
  driver_class::session(driver_config) do |kvs|
212
- kvs.add_sorted_set('example', 'element', 1)
213
- kvs.add_sorted_set('example2', 'element2', 1)
214
-
215
- expect{kvs.sorted_sets.delete('example2')}.to change{kvs.sorted_sets.length}.by(-1)
223
+ expect{kvs.sorted_sets.delete('anime')}.to change{kvs.sorted_sets.length}.by(-1)
216
224
  end
217
225
  end
218
226
 
219
227
  it 'call each' do
220
228
  driver_class::session(driver_config) do |kvs|
221
- kvs.add_sorted_set('example', 'element', 1)
222
- kvs.add_sorted_set('example2', 'element2', 1)
223
-
224
229
  kvs.sorted_sets.each do |key|
225
- expect(kvs.sorted_sets[key].length).not_to eq(0)
230
+ expect(key).to eq('anime')
226
231
  end
227
232
  end
228
233
  end
229
234
 
230
- it 'call each_member' do
235
+ it 'call has_key?' do
231
236
  driver_class::session(driver_config) do |kvs|
232
- kvs.add_sorted_set('example', 'element', 10)
233
- kvs.add_sorted_set('example', 'element2', 1)
234
-
235
- kvs.sorted_sets.each_member('example') do |member, score, position|
236
- expect(kvs.sorted_sets['example', member]).to eq(score)
237
- end
237
+ expect(kvs.sorted_sets.has_key?('anime')).to be_true
238
+ expect(kvs.sorted_sets.has_key?('nothing key')).to be_false
238
239
  end
239
240
  end
240
241
 
241
- it 'call has_key?' do
242
+ it 'call keys' do
242
243
  driver_class::session(driver_config) do |kvs|
243
- kvs.add_sorted_set('example', 'element', 10)
244
-
245
- expect(kvs.sorted_sets.has_key?('example')).to be_true
246
- expect(kvs.sorted_sets.has_key?('nothing key')).to be_false
244
+ expect(kvs.sorted_sets.keys.length).to eq(1)
247
245
  end
248
246
  end
249
247
 
250
- it 'call has_member?' do
248
+ it 'call length' do
251
249
  driver_class::session(driver_config) do |kvs|
252
- kvs.add_sorted_set('example', 'element', 10)
253
-
254
- expect(kvs.sorted_sets.has_member?('example','element')).to be_true
255
- expect(kvs.sorted_sets.has_member?('example','nothing member')).to be_false
256
- expect(kvs.sorted_sets.has_member?('nothing key', 'element')).to be_false
250
+ expect(kvs.sorted_sets.length).to eq(1)
257
251
  end
258
252
  end
259
253
 
260
- it 'call increment' do
261
- driver_class::session(driver_config) do |kvs|
262
- kvs.add_sorted_set('example', 'element', 10)
263
254
 
264
- expect{kvs.sorted_sets.increment('example','element', 1)}.to change{kvs.sorted_sets['example','element']}.by(1)
265
- expect{kvs.sorted_sets.increment('example','element', -1)}.to change{kvs.sorted_sets['example','element']}.by(-1)
255
+ context 'sorted_set' do
256
+ it 'call []' do
257
+ driver_class::session(driver_config) do |kvs|
258
+ expect(kvs.sorted_sets['anime']['nyaruko']).to eq(1024)
259
+ end
266
260
  end
267
- end
268
261
 
269
- it 'call keys' do
270
- driver_class::session(driver_config) do |kvs|
271
- kvs.add_sorted_set('example', 'element', 10)
272
- kvs.add_sorted_set('example2', 'element', 1)
262
+ it 'call []=' do
263
+ driver_class::session(driver_config) do |kvs|
264
+ expect{
265
+ kvs.sorted_sets['manga']['dragonball'] = 1
266
+ }.to change{
267
+ kvs.sorted_sets['manga'].length
268
+ }.by(1)
269
+
270
+ expect{
271
+ kvs.sorted_sets['anime']['nonnonbiyori'] = 1
272
+ }.to change{
273
+ kvs.sorted_sets['anime'].length
274
+ }.by(1)
275
+ end
276
+ end
273
277
 
274
- expect(kvs.sorted_sets.keys.length).to eq(2)
278
+ it 'call each' do
279
+ driver_class::session(driver_config) do |kvs|
280
+ kvs.sorted_sets['anime'].each do |member, score, position|
281
+ expect(kvs.sorted_sets['anime'][member]).to eq(score)
282
+ end
283
+ end
284
+ end
285
+
286
+ it 'call has_member?' do
287
+ driver_class::session(driver_config) do |kvs|
288
+ expect(kvs.sorted_sets['anime'].has_member?('nyaruko')).to be_true
289
+ expect(kvs.sorted_sets['anime'].has_member?('noting member')).to be_false
290
+ end
275
291
  end
276
- end
277
292
 
278
- it 'call length' do
279
- driver_class::session(driver_config) do |kvs|
280
- kvs.add_sorted_set('example', 'element', 10)
281
- kvs.add_sorted_set('example2', 'element', 1)
282
293
 
283
- expect(kvs.sorted_sets.length).to eq(2)
294
+ it 'call increment' do
295
+ driver_class::session(driver_config) do |kvs|
296
+ expect{kvs.sorted_sets['anime'].increment('nyaruko', 1)}.to change{kvs.sorted_sets['anime']['nyaruko']}.by(1)
297
+ expect{kvs.sorted_sets['anime'].increment('nyaruko', -1)}.to change{kvs.sorted_sets['anime']['nyaruko']}.by(-1)
298
+ end
284
299
  end
285
- end
286
300
 
287
- it 'call remove' do
288
- driver_class::session(driver_config) do |kvs|
289
- kvs.add_sorted_set('example', 'element', 10)
290
- kvs.add_sorted_set('example', 'element', 1)
301
+ it 'call length' do
302
+ driver_class::session(driver_config) do |kvs|
303
+ expect(kvs.sorted_sets['anime'].length).to eq(2)
304
+ end
305
+ end
306
+
307
+ it 'call members' do
308
+ driver_class::session(driver_config) do |kvs|
309
+ expect(kvs.sorted_sets['anime'].members.length).to eq(2)
310
+ end
311
+ end
291
312
 
292
- expect{kvs.sorted_sets.remove('example', 'element')}.to change{kvs.sorted_sets.count('example')}.by(-1)
313
+ it 'call remove' do
314
+ driver_class::session(driver_config) do |kvs|
315
+ expect{
316
+ kvs.sorted_sets['anime'].remove('haganai')
317
+ }.to change{
318
+ kvs.sorted_sets['anime'].length
319
+ }.by(-1)
320
+ end
293
321
  end
322
+
294
323
  end
324
+
295
325
  end
296
326
  end
297
327
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_kvs_driver-redis_driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - alfa-jpn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-12 00:00:00.000000000 Z
11
+ date: 2013-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 0.1.6
89
+ version: 0.2.1
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 0.1.6
96
+ version: 0.2.1
97
97
  description: rails_kvs_driver is available to use namespace and connection pool and
98
98
  ruby-like methods of kvs.
99
99
  email: