rails_kvs_driver-redis_driver 0.0.2 → 0.1.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: 9cd3b2f82f964c275f88dbcd4cd227d6326566a1
4
- data.tar.gz: 9245486b6b16e8fdc1164c2f8ba758a651a164b5
3
+ metadata.gz: 1ad02b5b22684d4f7e38ebf426d09d8e5994ca92
4
+ data.tar.gz: 2054be8ce2e783dae350628f083ae31ebb0a21a7
5
5
  SHA512:
6
- metadata.gz: 40adcc459602fdd6f04296ec6bc5ef2c1f181794f1cf8c8462e25f56d4ce7adff15347a383c5b22d80d3daefb73120873b75d31da33814b5ba0ccdb4ecf0eea0
7
- data.tar.gz: d59a5c3a354d22ba5109c9a4566afd609d1d0752836821c7fabbd8460e623ba6d911716ce90936d2f7d47dbf8306eeff2cc624f460c0c224f60d6fc80069d1a6
6
+ metadata.gz: e5b6d6e5379206846af12e7e1fb892888c6e03ccbe57c2131a2f3caaae81f8f8d75aa8d923658ea3d58256fb2cd4b7bdcc5a9dc450833cb2a406b597de4a35bf
7
+ data.tar.gz: dc230b28c5ae8ff2e7bbe202a4c771b48dc4452846534fe39ec8b1b0b50473a4064ba17648421a0b990c3e33b3e1d4b856135e3009ab95b5a07d9e34ad79164c
data/README.md CHANGED
@@ -16,9 +16,106 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install rails_kvs_driver-redis_driver
18
18
 
19
- ## Usage
19
+ ## Usage(function of [Rails_Kvs_Driver](https://github.com/alfa-jpn/rails-kvs-driver).)
20
+
21
+ ### define driver configuration
22
+ ``` ruby
23
+ driver_config = {
24
+ :host => 'localhost', # host of redis
25
+ :port => 6379, # port of redis
26
+ :namespace => 'Example', # namespace of key
27
+ :timeout_sec => 5, # timeout seconds
28
+ :pool_size => 5, # connection pool size
29
+ :config_key => :none # This key is option. (default=:none)
30
+ # when set this key.
31
+ # will refer to a connection-pool based on config_key,
32
+ # even if driver setting is the same without this key.
33
+ }
34
+ ```
35
+
36
+ ### connect and exec basic (set/get/delete)
37
+ session method enables connection pool.
38
+ ``` ruby
39
+ RailsKvsDriver::RedisDriver::Driver::session(driver_config) do |redis|
40
+
41
+ # set key to redis.
42
+ redis['animation'] = 'good!'
43
+ redis['nyarukosan'] = 'kawaii!'
44
+
45
+ # get value from redis.
46
+ puts redis['animation'] # => 'good!'
47
+
48
+ # exec each
49
+ redis.each do |key,value|
50
+ puts "#{key} is #{value}!" # => animation is good!!
51
+ # => nyarukosan is kawaii!!
52
+ end
53
+
54
+ # check existed.
55
+ redis.has_key?('animation') # => true
56
+
57
+ # get all keys.
58
+ redis.keys # => ['animation', 'nyarukosan']
59
+
60
+ # delete key from redis.
61
+ redis.delete('nyarukosan')
62
+
63
+ # delete all keys.
64
+ redis.delete_all
65
+
66
+ end
67
+ ```
68
+
69
+ ### sorted set
70
+ ``` ruby
71
+ RailsKvsDriver::RedisDriver::Driver::session(driver_config) do |redis|
72
+
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
+
78
+ # 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
+
82
+ # execute the block of code for each member of sorted set.
83
+ redis.sorted_sets.each_member('animations', true) do |member, score, position|
84
+ puts "#{position+1}:#{member} is #{score}pt." # => '1:nyarukosan is 10pt.'
85
+ # => '2:nonnonbiyori is 5pt.'
86
+ # => '3:kiniromosaic is 1pt.'
87
+ end
88
+
89
+ # 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
+
106
+ # 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
114
+
115
+ end
116
+ ```
117
+
20
118
 
21
- comming soon.
22
119
 
23
120
  ## Contributing
24
121
 
@@ -1,5 +1,5 @@
1
1
  module RailsKvsDriver
2
2
  module RedisDriver
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -5,21 +5,17 @@ require "redis"
5
5
  module RailsKvsDriver::RedisDriver
6
6
  class Driver < RailsKvsDriver::Base
7
7
  # connect with driver config.
8
- # @return [Boolean] result
9
- def connect
10
- begin
11
- @kvs_inst = Redis.new(host: @driver_config[:host], port: @driver_config[:port])
12
- return true
13
- rescue
14
- return false
15
- end
8
+ # @param driver_config [Hash] driver config.
9
+ # @return [Object] instance of key-value store.
10
+ def self.connect(driver_config)
11
+ Redis.new(host: driver_config[:host], port: driver_config[:port])
16
12
  end
17
13
 
18
14
  # get value from kvs.
19
15
  # @param key [String] key.
20
- # @return [String] value.
16
+ # @return [String] value. when doesn't exist, nil.
21
17
  def [](key)
22
- @kvs_inst.get(safe_key(key))
18
+ @kvs_instance.get(safe_key(key))
23
19
  end
24
20
 
25
21
  # set value to kvs.
@@ -27,38 +23,30 @@ module RailsKvsDriver::RedisDriver
27
23
  # @param value [String] value.
28
24
  # @return [Boolean] result
29
25
  def []=(key, value)
30
- @kvs_inst.set(safe_key(key), value)
31
- end
32
-
33
- # get all keys from kvs.
34
- # @return [Array<String>] array of key names.
35
- def all_keys
36
- result = Array.new
37
- pattern = safe_key('*')
38
- header_len = pattern.length - 1
39
-
40
- @kvs_inst.keys(pattern).each do |key|
41
- result.push key[header_len .. -1]
42
- end
43
-
44
- return result
26
+ @kvs_instance.set(safe_key(key), value)
45
27
  end
46
28
 
47
29
  # delete key from kvs.
48
30
  # @return [Boolean] result.
49
31
  def delete(key)
50
- (@kvs_inst.del(safe_key(key)) == 1)
32
+ (@kvs_instance.del(safe_key(key)) == 1)
51
33
  end
52
34
 
53
35
  # delete all keys from kvs.
54
36
  # @return [Boolean] result.
55
37
  def delete_all
56
- keys = @kvs_inst.keys(safe_key('*'))
57
- del_num = @kvs_inst.del(keys) if keys.length > 0
38
+ keys = @kvs_instance.keys(safe_key('*'))
39
+ del_num = @kvs_instance.del(keys) if keys.length > 0
58
40
 
59
41
  (del_num == keys.length)
60
42
  end
61
43
 
44
+ # get all keys from kvs.
45
+ # @return [Array<String>] array of key names.(only having string value)
46
+ def keys
47
+ keys_with_type('string')
48
+ end
49
+
62
50
  # add sorted set to kvs.
63
51
  # when the key doesn't exist, it's made newly.
64
52
  # @note same as sorted set of redis. refer to redis.
@@ -68,31 +56,40 @@ module RailsKvsDriver::RedisDriver
68
56
  # @param score [Float] score of sorted set.
69
57
  # @return [Boolean] result.
70
58
  def add_sorted_set(key, member, score)
71
- @kvs_inst.zadd(safe_key(key), score, member)
59
+ @kvs_instance.zadd(safe_key(key), score, member)
72
60
  end
73
61
 
74
- # remove sorted set from kvs.
75
- # This function doesn't delete a key.
62
+ # count members of sorted set
76
63
  # @note same as sorted set of redis. refer to redis.
77
64
  #
78
- # @param key [String] key of sorted set.
79
- # @param member [String] member of sorted set.
80
- # @return [Boolean] result.
81
- # @abstract remove sorted set from kvs.
82
- def remove_sorted_set(key, member)
83
- @kvs_inst.zrem(safe_key(key), member)
65
+ # @param key [String] key of sorted set.
66
+ # @return [Integer] members num
67
+ def count_sorted_set_member(key)
68
+ @kvs_instance.zcard(safe_key(key))
84
69
  end
85
70
 
86
- # increment score of member from sorted set.
71
+ # get array of sorted set.
87
72
  # @note same as sorted set of redis. refer to redis.
88
73
  #
89
- # @param key [String] key of sorted set.
90
- # @param member [String] member of sorted set.
91
- # @param score [Float] increment score.
92
- # @return [Float] value after increment
93
- # @abstract increment score of member from sorted set.
94
- def increment_sorted_set(key, member, score)
95
- @kvs_inst.zincrby(safe_key(key), score, member)
74
+ # @param key [String] key of sorted set.
75
+ # @param start [Integer] start index
76
+ # @param stop [Integer] stop index
77
+ # @param reverse [Boolean] order by desc
78
+ # @return [Array<String, Float>>] array of the member and score. when doesn't exist, nil.
79
+ def get_sorted_set(key, start=0, stop=-1, reverse=false)
80
+ if reverse
81
+ result = @kvs_instance.zrevrange(safe_key(key), start, stop, with_scores: true)
82
+ else
83
+ result = @kvs_instance.zrange(safe_key(key), start, stop, with_scores: true)
84
+ end
85
+
86
+ return (result.length == 0) ? nil : result
87
+ end
88
+
89
+ # get all sorted_set keys.
90
+ # @return [Array<String>] array of key names.(only having sorted_set)
91
+ def get_sorted_set_keys
92
+ keys_with_type('zset')
96
93
  end
97
94
 
98
95
  # get the score of member.
@@ -101,35 +98,30 @@ module RailsKvsDriver::RedisDriver
101
98
  # @param key [String] key of sorted set.
102
99
  # @param member [String] member of sorted set.
103
100
  # @return [Float] score of member.
104
- # @abstract get the score of member.
105
- def sorted_set_score(key, member)
106
- @kvs_inst.zscore(safe_key(key), member)
101
+ def get_sorted_set_score(key, member)
102
+ @kvs_instance.zscore(safe_key(key), member)
107
103
  end
108
104
 
109
- # get array of sorted set.
105
+ # increment score of member from sorted set.
110
106
  # @note same as sorted set of redis. refer to redis.
111
107
  #
112
- # @param key [String] key of sorted set.
113
- # @param start [Integer] start index
114
- # @param stop [Integer] stop index
115
- # @param reverse [Boolean] order by desc
116
- # @return [Array<String, Float>>] array of the member and score.
117
- # @abstract get array of sorted set.
118
- def sorted_set(key, start=0, stop=-1, reverse=false)
119
- if reverse
120
- @kvs_inst.zrevrange(safe_key(key), start, stop, with_scores: true)
121
- else
122
- @kvs_inst.zrange(safe_key(key), start, stop, with_scores: true)
123
- end
108
+ # @param key [String] key of sorted set.
109
+ # @param member [String] member of sorted set.
110
+ # @param score [Float] increment score.
111
+ # @return [Float] value after increment
112
+ def increment_sorted_set(key, member, score)
113
+ @kvs_instance.zincrby(safe_key(key), score, member)
124
114
  end
125
115
 
126
- # count members of sorted set
116
+ # remove sorted set from kvs.
117
+ # This function doesn't delete a key.
127
118
  # @note same as sorted set of redis. refer to redis.
128
119
  #
129
- # @param key [String] key of sorted set.
130
- # @return [Integer] members num
131
- def count_sorted_set_member(key)
132
- @kvs_inst.zcard(safe_key(key))
120
+ # @param key [String] key of sorted set.
121
+ # @param member [String] member of sorted set.
122
+ # @return [Boolean] result.
123
+ def remove_sorted_set(key, member)
124
+ @kvs_instance.zrem(safe_key(key), member)
133
125
  end
134
126
 
135
127
  private
@@ -139,5 +131,21 @@ module RailsKvsDriver::RedisDriver
139
131
  def safe_key(key)
140
132
  "#{@driver_config[:namespace]}::#{key}"
141
133
  end
134
+
135
+ # get keys with type.
136
+ #
137
+ # @param [String] type of key.
138
+ # @return [Array<String>] array of keys.
139
+ def keys_with_type(type)
140
+ result = Array.new
141
+ pattern = safe_key('*')
142
+ header_len = pattern.length - 1
143
+
144
+ @kvs_instance.keys(pattern).each do |key|
145
+ result.push key[header_len .. -1] if @kvs_instance.type(key) == type
146
+ end
147
+
148
+ return result
149
+ end
142
150
  end
143
151
  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.0.3"
27
+ spec.add_dependency "rails_kvs_driver", "0.1.5"
28
28
  end
@@ -25,106 +25,263 @@ shared_examples_for 'RailsKvsDriver example' do |driver_class, driver_config|
25
25
  end
26
26
  end
27
27
 
28
- it 'call set value' do
29
- driver_class::session(driver_config) do |kvs|
30
- expect{ kvs['example'] = 'nico-nico' }.to change{ kvs.all_keys.length }.by(1)
28
+ context 'override methods' do
29
+ it 'call []' do
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
34
+ end
31
35
  end
32
- end
33
36
 
34
- it 'call get value' do
35
- driver_class::session(driver_config) do |kvs|
36
- expect{ kvs['example'] = 'nico-nico' }.to change{ kvs.all_keys.length }.by(1)
37
- expect(kvs['example']).to eq('nico-nico')
37
+ it 'call []=' do
38
+ driver_class::session(driver_config) do |kvs|
39
+ expect{ kvs['example'] = 'nico-nico' }.to change{ kvs.keys.length }.by(1)
40
+ end
38
41
  end
39
- end
40
42
 
41
- it 'call all keys' do
42
- driver_class::session(driver_config) do |kvs|
43
- expect{ kvs['example'] = 'nico-nico' }.to change{ kvs.all_keys.length }.by(1)
44
- expect(kvs.all_keys.length).to eq(1)
43
+ it 'call add_sorted_set' do
44
+ driver_class::session(driver_config) do |kvs|
45
+ expect{
46
+ kvs.add_sorted_set('example', 'element', 1)
47
+ }.to change{ kvs.get_sorted_set_keys.length }.by(1)
48
+ end
45
49
  end
46
- end
47
50
 
48
- it 'call delete value' do
49
- driver_class::session(driver_config) do |kvs|
50
- kvs['example'] = 'nico-nico'
51
- kvs['example2'] = 'movie'
51
+ it 'call count_sorted_set_member' do
52
+ driver_class::session(driver_config) do |kvs|
53
+ kvs.add_sorted_set('example', 'element1', 5)
54
+ kvs.add_sorted_set('example', 'element2', 5)
55
+ kvs.add_sorted_set('example', 'element3', 5)
56
+ expect(kvs.count_sorted_set_member('example')).to eq(3)
57
+ end
58
+ end
52
59
 
53
- expect{ kvs.delete('example') }.to change{ kvs.all_keys.length }.by(-1)
60
+ it 'call delete' do
61
+ driver_class::session(driver_config) do |kvs|
62
+ kvs['example'] = 'nico-nico'
63
+ kvs['example2'] = 'movie'
54
64
 
55
- expect(kvs['example']).to eq(nil)
56
- expect(kvs['example2']).to eq('movie')
65
+ expect{ kvs.delete('example') }.to change{ kvs.keys.length }.by(-1)
66
+
67
+ expect(kvs.has_key?('example')).to be_false
68
+ expect(kvs.has_key?('example2')).to be_true
69
+ end
57
70
  end
58
- end
59
71
 
60
- it 'call delete_all' do
61
- driver_class::session(driver_config) do |kvs|
62
- kvs['example'] = 'nico-nico'
63
- kvs['example2'] = 'movie'
72
+ it 'call delete_all' do
73
+ driver_class::session(driver_config) do |kvs|
74
+ kvs['example'] = 'nico-nico'
75
+ kvs['example2'] = 'movie'
76
+
77
+ expect{ kvs.delete_all }.to change{ kvs.keys.length }.by(-2)
78
+ end
79
+ end
80
+
81
+ it 'call get_sorted_set' do
82
+ driver_class::session(driver_config) do |kvs|
83
+ kvs.add_sorted_set('example', 'element1', 1)
84
+ kvs.add_sorted_set('example', 'element5', 5)
85
+ kvs.add_sorted_set('example', 'element2', 2)
64
86
 
65
- expect{ kvs.delete_all }.to change{ kvs.all_keys.length }.by(-2)
87
+ sorted_set = kvs.get_sorted_set('example')
66
88
 
67
- expect(kvs['example']).to eq(nil)
68
- expect(kvs['example2']).to eq(nil)
89
+ expect(sorted_set[0][0]).to eq('element1')
90
+ expect(sorted_set[1][0]).to eq('element2')
91
+ expect(sorted_set[2][0]).to eq('element5')
92
+
93
+ expect(kvs.get_sorted_set('nothing key')).to be_nil
94
+ end
69
95
  end
70
- end
71
96
 
72
- it 'call add_sorted_set' do
73
- driver_class::session(driver_config) do |kvs|
74
- expect{
97
+ it 'call get_sorted_set_keys' do
98
+ driver_class::session(driver_config) do |kvs|
99
+ kvs['example'] = 'nico-nico'
100
+ kvs.add_sorted_set('example0_ss', 'element0', 5)
101
+ kvs.add_sorted_set('example1_ss', 'element0', 5)
102
+
103
+ expect(kvs.get_sorted_set_keys.length).to eq(2)
104
+ end
105
+ end
106
+
107
+ it 'call get_sorted_set_score' do
108
+ driver_class::session(driver_config) do |kvs|
109
+ kvs.add_sorted_set('example', 'element5', 5)
110
+ expect(kvs.get_sorted_set('example')[0][1]).to eq(5)
111
+ end
112
+ end
113
+
114
+ it 'call increment_sorted_set' do
115
+ driver_class::session(driver_config) do |kvs|
75
116
  kvs.add_sorted_set('example', 'element', 1)
76
- }.to change{ kvs.all_keys.length }.by(1)
117
+
118
+ expect{
119
+ kvs.increment_sorted_set('example', 'element', 10)
120
+ }.to change{ kvs.get_sorted_set_score('example', 'element') }.by(10)
121
+ end
77
122
  end
78
- end
79
123
 
80
- it 'call remove_sorted_set' do
81
- driver_class::session(driver_config) do |kvs|
82
- kvs.add_sorted_set('example', 'element', 1)
83
- kvs.add_sorted_set('example', 'element2', 1)
124
+ it 'call has_key?' do
125
+ driver_class::session(driver_config) do |kvs|
126
+ kvs['example'] = 'nico-nico'
84
127
 
85
- expect{
86
- kvs.remove_sorted_set('example', 'element')
87
- }.to change{ kvs.count_sorted_set_member('example') }.by(-1)
128
+ expect(kvs.has_key?('example')).to be_true
129
+ expect(kvs.has_key?('nothing key')).to be_false
130
+ end
88
131
  end
89
- end
90
132
 
91
- it 'call increment_sorted_set' do
92
- driver_class::session(driver_config) do |kvs|
93
- kvs.add_sorted_set('example', 'element', 1)
133
+ it 'call keys' do
134
+ driver_class::session(driver_config) do |kvs|
135
+ kvs['example0'] = 'nico-nico'
136
+ kvs['example1'] = 'nico-nico'
137
+ kvs.add_sorted_set('example_ss', 'element5', 5)
138
+
139
+ expect(kvs.keys.length).to eq(2)
140
+ end
141
+ end
142
+
143
+ it 'call remove_sorted_set' do
144
+ driver_class::session(driver_config) do |kvs|
145
+ kvs.add_sorted_set('example', 'element', 1)
146
+ kvs.add_sorted_set('example', 'element2', 1)
94
147
 
95
- expect{
96
- kvs.increment_sorted_set('example', 'element', 10)
97
- }.to change{ kvs.sorted_set_score('example', 'element') }.by(10)
148
+ expect{
149
+ kvs.remove_sorted_set('example', 'element')
150
+ }.to change{ kvs.count_sorted_set_member('example') }.by(-1)
151
+ end
98
152
  end
99
153
  end
100
154
 
101
- it 'call sorted_set' do
102
- driver_class::session(driver_config) do |kvs|
103
- kvs.add_sorted_set('example', 'element1', 1)
104
- kvs.add_sorted_set('example', 'element5', 5)
105
- kvs.add_sorted_set('example', 'element2', 2)
106
155
 
107
- sorted_set = kvs.sorted_set('example')
108
156
 
109
- expect(sorted_set[0][0]).to eq('element1')
110
- expect(sorted_set[1][0]).to eq('element2')
111
- expect(sorted_set[2][0]).to eq('element5')
157
+
158
+ context 'inheritance methods' do
159
+
160
+ it 'call each' do
161
+ driver_class::session(driver_config) do |kvs|
162
+ kvs['example0'] = 'nico-nico0'
163
+ kvs['example1'] = 'nico-nico1'
164
+
165
+ kvs.each do |key, value|
166
+ expect(value).to eq(kvs[key])
167
+ end
168
+ end
112
169
  end
113
- end
114
170
 
115
- it 'call sorted_set_score' do
116
- driver_class::session(driver_config) do |kvs|
117
- kvs.add_sorted_set('example', 'element5', 5)
118
- expect(kvs.sorted_set('example')[0][1]).to eq(5)
171
+ it 'call length' do
172
+ driver_class::session(driver_config) do |kvs|
173
+ kvs['example0'] = 'nico-nico0'
174
+ kvs['example1'] = 'nico-nico1'
175
+
176
+ expect(kvs.length).to eq(2)
177
+ end
119
178
  end
120
- end
121
179
 
122
- it 'call count_sorted_set_member' do
123
- driver_class::session(driver_config) do |kvs|
124
- kvs.add_sorted_set('example', 'element1', 5)
125
- kvs.add_sorted_set('example', 'element2', 5)
126
- kvs.add_sorted_set('example', 'element3', 5)
127
- expect(kvs.count_sorted_set_member('example')).to eq(3)
180
+ context 'sorted_sets' do
181
+
182
+ it 'call []' do
183
+ 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)
189
+ end
190
+ end
191
+
192
+ it 'call []=' do
193
+ 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)
198
+ end
199
+ end
200
+
201
+ it 'call count' do
202
+ driver_class::session(driver_config) do |kvs|
203
+ kvs.add_sorted_set('example', 'element', 1)
204
+ kvs.add_sorted_set('example', 'element2', 1)
205
+
206
+ expect(kvs.sorted_sets.count('example')).to eq(2)
207
+ end
208
+ end
209
+
210
+ it 'call delete' do
211
+ 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)
216
+ end
217
+ end
218
+
219
+ it 'call each' do
220
+ 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
+ kvs.sorted_sets.each do |key|
225
+ expect(kvs.sorted_sets[key].length).not_to eq(0)
226
+ end
227
+ end
228
+ end
229
+
230
+ it 'call each_member' do
231
+ 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
238
+ end
239
+ end
240
+
241
+ it 'call has_key?' do
242
+ 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
247
+ end
248
+ end
249
+
250
+ it 'call increment' do
251
+ driver_class::session(driver_config) do |kvs|
252
+ kvs.add_sorted_set('example', 'element', 10)
253
+
254
+ expect{kvs.sorted_sets.increment('example','element', 1)}.to change{kvs.sorted_sets['example','element']}.by(1)
255
+ expect{kvs.sorted_sets.increment('example','element', -1)}.to change{kvs.sorted_sets['example','element']}.by(-1)
256
+ end
257
+ end
258
+
259
+ it 'call keys' do
260
+ driver_class::session(driver_config) do |kvs|
261
+ kvs.add_sorted_set('example', 'element', 10)
262
+ kvs.add_sorted_set('example2', 'element', 1)
263
+
264
+ expect(kvs.sorted_sets.keys.length).to eq(2)
265
+ end
266
+ end
267
+
268
+ it 'call length' do
269
+ driver_class::session(driver_config) do |kvs|
270
+ kvs.add_sorted_set('example', 'element', 10)
271
+ kvs.add_sorted_set('example2', 'element', 1)
272
+
273
+ expect(kvs.sorted_sets.length).to eq(2)
274
+ end
275
+ end
276
+
277
+ it 'call remove' do
278
+ driver_class::session(driver_config) do |kvs|
279
+ kvs.add_sorted_set('example', 'element', 10)
280
+ kvs.add_sorted_set('example', 'element', 1)
281
+
282
+ expect{kvs.sorted_sets.remove('example', 'element')}.to change{kvs.sorted_sets.count('example')}.by(-1)
283
+ end
284
+ end
128
285
  end
129
286
  end
130
287
  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.0.2
4
+ version: 0.1.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-08 00:00:00.000000000 Z
11
+ date: 2013-11-11 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.0.3
89
+ version: 0.1.5
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.0.3
96
+ version: 0.1.5
97
97
  description: redis driver for rails kvs driver.
98
98
  email:
99
99
  - a.nkmr.ja@gmail.com