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 +4 -4
- data/README.md +99 -2
- data/lib/rails_kvs_driver/redis_driver/version.rb +1 -1
- data/lib/rails_kvs_driver/redis_driver.rb +74 -66
- data/rails_kvs_driver-redis_driver.gemspec +1 -1
- data/spec/common_example.rb +227 -70
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ad02b5b22684d4f7e38ebf426d09d8e5994ca92
|
4
|
+
data.tar.gz: 2054be8ce2e783dae350628f083ae31ebb0a21a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
@@ -5,21 +5,17 @@ require "redis"
|
|
5
5
|
module RailsKvsDriver::RedisDriver
|
6
6
|
class Driver < RailsKvsDriver::Base
|
7
7
|
# connect with driver config.
|
8
|
-
# @
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
@
|
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
|
-
@
|
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
|
-
(@
|
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 = @
|
57
|
-
del_num = @
|
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
|
-
@
|
59
|
+
@kvs_instance.zadd(safe_key(key), score, member)
|
72
60
|
end
|
73
61
|
|
74
|
-
#
|
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
|
79
|
-
# @
|
80
|
-
|
81
|
-
|
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
|
-
#
|
71
|
+
# get array of sorted set.
|
87
72
|
# @note same as sorted set of redis. refer to redis.
|
88
73
|
#
|
89
|
-
# @param key
|
90
|
-
# @param
|
91
|
-
# @param
|
92
|
-
# @
|
93
|
-
# @
|
94
|
-
def
|
95
|
-
|
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
|
-
|
105
|
-
|
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
|
-
#
|
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
|
113
|
-
# @param
|
114
|
-
# @param
|
115
|
-
# @
|
116
|
-
|
117
|
-
|
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
|
-
#
|
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
|
130
|
-
# @
|
131
|
-
|
132
|
-
|
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
|
data/spec/common_example.rb
CHANGED
@@ -25,106 +25,263 @@ shared_examples_for 'RailsKvsDriver example' do |driver_class, driver_config|
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
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
|
-
|
56
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
87
|
+
sorted_set = kvs.get_sorted_set('example')
|
66
88
|
|
67
|
-
|
68
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
86
|
-
kvs.
|
87
|
-
|
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
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
110
|
-
|
111
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
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-
|
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.
|
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.
|
96
|
+
version: 0.1.5
|
97
97
|
description: redis driver for rails kvs driver.
|
98
98
|
email:
|
99
99
|
- a.nkmr.ja@gmail.com
|