rails_kvs_driver 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails_kvs_driver/common_methods/listable.rb +37 -0
- data/lib/rails_kvs_driver/defined_base_method.rb +11 -21
- data/lib/rails_kvs_driver/lists/list.rb +116 -0
- data/lib/rails_kvs_driver/lists/lists.rb +54 -0
- data/lib/rails_kvs_driver/sorted_sets/sorted_set.rb +13 -1
- data/lib/rails_kvs_driver/sorted_sets/sorted_sets.rb +5 -23
- data/lib/rails_kvs_driver/version.rb +1 -1
- data/lib/rails_kvs_driver.rb +124 -0
- data/spec/common_example.rb +82 -65
- data/spec/rails_kvs_driver/defined_base_method_spec.rb +12 -0
- data/spec/rails_kvs_driver/lists/list_spec.rb +57 -0
- data/spec/rails_kvs_driver/lists/lists_spec.rb +65 -0
- data/spec/rails_kvs_driver/sorted_sets/sorted_set_spec.rb +15 -2
- data/spec/rails_kvs_driver/sorted_sets/sorted_sets_spec.rb +11 -3
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c26761a67864a1eec96c0788df35795c30439d7
|
4
|
+
data.tar.gz: d0aa335dac73aeb03151d00684a9c502189c6006
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0828ce5858f49a0fa9228ffda88f394c06db0e7287c5cf212b9f7dc3ff9e2c3c26468a75d10999d9614630c32f92dff8190b4d4479c72b5b4eb1b355f680a7d
|
7
|
+
data.tar.gz: cbc5f444e47da2c704760e39f6093440469da71d748c3a38ba1a9e08bc95b8eed9a846b8f39be502bb86cf617fc0f1923a83cd7d0067898438a2b02a59376eb2
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module RailsKvsDriver
|
2
|
+
module CommonMethods
|
3
|
+
# common functions for keys.
|
4
|
+
module Listable
|
5
|
+
# execute the block of code for each sorted_set.
|
6
|
+
#
|
7
|
+
# @param &block [{|key, value| }] each the block of code for each key having string, and value.
|
8
|
+
def each
|
9
|
+
keys.each {|key| yield key, self[key] }
|
10
|
+
end
|
11
|
+
|
12
|
+
# kvs check empty.
|
13
|
+
#
|
14
|
+
# @return [Boolean] result.
|
15
|
+
def empty?
|
16
|
+
(length<1)
|
17
|
+
end
|
18
|
+
|
19
|
+
# check key in sorted set.
|
20
|
+
#
|
21
|
+
# @param key [String] key name.
|
22
|
+
# @return [Boolean] result.
|
23
|
+
def has_key?(key)
|
24
|
+
keys.include?(key)
|
25
|
+
end
|
26
|
+
|
27
|
+
# get length of sorted_set.
|
28
|
+
#
|
29
|
+
# @return [Integer] length of keys.
|
30
|
+
def length
|
31
|
+
keys.length
|
32
|
+
end
|
33
|
+
|
34
|
+
alias size length
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,7 +1,12 @@
|
|
1
|
+
require 'rails_kvs_driver/lists/lists'
|
1
2
|
require 'rails_kvs_driver/sorted_sets/sorted_sets'
|
3
|
+
require 'rails_kvs_driver/common_methods/listable'
|
2
4
|
|
3
5
|
module RailsKvsDriver
|
4
6
|
module DefinedBaseMethod
|
7
|
+
include RailsKvsDriver::CommonMethods::Listable
|
8
|
+
include Enumerable
|
9
|
+
|
5
10
|
# initialize driver.
|
6
11
|
# @param kvs_instance [Object] instance of key-value store.
|
7
12
|
# @param driver_config [Hash] driver config.
|
@@ -27,33 +32,18 @@ module RailsKvsDriver
|
|
27
32
|
set(key, value)
|
28
33
|
end
|
29
34
|
|
30
|
-
# return initialized
|
35
|
+
# return initialized SortedSets class.
|
31
36
|
#
|
32
|
-
# @return [RailsKvsDriver::SortedSets]
|
37
|
+
# @return [RailsKvsDriver::SortedSets::SortedSets] SortedSets
|
33
38
|
def sorted_sets
|
34
39
|
SortedSets::SortedSets.new(self)
|
35
40
|
end
|
36
41
|
|
37
|
-
#
|
38
|
-
# @param &block [{|key, value| }] each the block of code for each key having string, and value.
|
39
|
-
def each
|
40
|
-
keys.each {|key| yield key, self[key] }
|
41
|
-
end
|
42
|
-
|
43
|
-
# check key in redis.
|
44
|
-
#
|
45
|
-
# @param key [String] key name
|
46
|
-
# @return [Boolean] result
|
47
|
-
def has_key?(key)
|
48
|
-
!(self[key].nil?)
|
49
|
-
end
|
50
|
-
|
51
|
-
# get length of keys.
|
42
|
+
# return initialized lists class.
|
52
43
|
#
|
53
|
-
# @return [
|
54
|
-
def
|
55
|
-
|
44
|
+
# @return [RailsKvsDriver::Lists::Lists] lists
|
45
|
+
def lists
|
46
|
+
Lists::Lists.new(self)
|
56
47
|
end
|
57
|
-
|
58
48
|
end
|
59
49
|
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module RailsKvsDriver
|
2
|
+
module Lists
|
3
|
+
class List
|
4
|
+
attr_accessor :driver_instance
|
5
|
+
attr_accessor :key
|
6
|
+
|
7
|
+
# initialize list
|
8
|
+
#
|
9
|
+
# @param driver_instance [RailsKvsDriver::Base] instance of driver.
|
10
|
+
# @param key [String] key of sorted_set.
|
11
|
+
def initialize(driver_instance, key)
|
12
|
+
@driver_instance = driver_instance
|
13
|
+
@key = key
|
14
|
+
end
|
15
|
+
|
16
|
+
# get value of the list.
|
17
|
+
# when the key or index doesn't exist, return nil.
|
18
|
+
#
|
19
|
+
# @param index [Integer] index of the list.
|
20
|
+
# @return [String] value
|
21
|
+
def [](index)
|
22
|
+
@driver_instance.get_list_value(@key, index)
|
23
|
+
end
|
24
|
+
|
25
|
+
# set value to index of the list.
|
26
|
+
# when the key or index doesn't exist, raise error.
|
27
|
+
#
|
28
|
+
# @param index [Integer] index of the list.
|
29
|
+
# @param value [String] value
|
30
|
+
def []=(index, value)
|
31
|
+
@driver_instance.set_list_value(@key, index, value)
|
32
|
+
end
|
33
|
+
|
34
|
+
# delete value from list.
|
35
|
+
#
|
36
|
+
# @param value [String] delete value.
|
37
|
+
def delete(value)
|
38
|
+
@driver_instance.delete_list_value(@key, value)
|
39
|
+
end
|
40
|
+
|
41
|
+
# delete at index from list.
|
42
|
+
#
|
43
|
+
# @param index [Integer] index of the list.
|
44
|
+
def delete_at(index)
|
45
|
+
@driver_instance.delete_list_value_at(@key, index)
|
46
|
+
end
|
47
|
+
|
48
|
+
# execute the block of code for each value of the list.
|
49
|
+
#
|
50
|
+
# @param limit [Integer] limit number to acquire at a time. (default=1000)
|
51
|
+
# @param &block [{|index, value| }] execute the block of code for each value of the list.
|
52
|
+
def each(limit=1000)
|
53
|
+
count = length
|
54
|
+
position = 0
|
55
|
+
|
56
|
+
while position < count
|
57
|
+
@driver_instance.get_list_values(@key, position, position + (limit-1)).each do |value|
|
58
|
+
yield position, value
|
59
|
+
position += 1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# check if a value is included.
|
65
|
+
#
|
66
|
+
# @param value [String] value
|
67
|
+
# @return [Boolean] result
|
68
|
+
def include?(value)
|
69
|
+
each do |list_value|
|
70
|
+
return true if list_value == value
|
71
|
+
end
|
72
|
+
return false
|
73
|
+
end
|
74
|
+
|
75
|
+
# return length of the list.
|
76
|
+
def length
|
77
|
+
@driver_instance.count_list_value(@key)
|
78
|
+
end
|
79
|
+
|
80
|
+
# push value to first of the list.
|
81
|
+
# when the key doesn't exist, it's made newly list.
|
82
|
+
#
|
83
|
+
# @param value [String] value.
|
84
|
+
def push_fist(value)
|
85
|
+
@driver_instance.push_list_first(@key, value)
|
86
|
+
end
|
87
|
+
|
88
|
+
# push value to last of the list.
|
89
|
+
# when the key doesn't exist, it's made newly list.
|
90
|
+
#
|
91
|
+
# @param value [String] value.
|
92
|
+
def push_last(value)
|
93
|
+
@driver_instance.push_list_last(@key, value)
|
94
|
+
end
|
95
|
+
|
96
|
+
# pop value from first of the list.
|
97
|
+
# when the key doesn't exist or is empty. return nil.
|
98
|
+
#
|
99
|
+
# @return [String] value of the key.
|
100
|
+
def pop_first
|
101
|
+
@driver_instance.pop_list_first(@key)
|
102
|
+
end
|
103
|
+
|
104
|
+
# pop value from last of the list.
|
105
|
+
# when the key doesn't exist or is empty. return nil.
|
106
|
+
#
|
107
|
+
# @return [String] value of the key.
|
108
|
+
def pop_last
|
109
|
+
@driver_instance.pop_list_last(@key)
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
alias size length
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rails_kvs_driver/lists/list'
|
2
|
+
require 'rails_kvs_driver/common_methods/listable'
|
3
|
+
|
4
|
+
module RailsKvsDriver
|
5
|
+
module Lists
|
6
|
+
class Lists
|
7
|
+
include RailsKvsDriver::CommonMethods::Listable
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
attr_accessor :driver_instance
|
11
|
+
|
12
|
+
# initialize lists
|
13
|
+
#
|
14
|
+
# @param driver_instance [RailsKvsDriver::Base]
|
15
|
+
def initialize(driver_instance)
|
16
|
+
@driver_instance = driver_instance
|
17
|
+
end
|
18
|
+
|
19
|
+
# get list.
|
20
|
+
#
|
21
|
+
# @param key [String] sorted_set key.
|
22
|
+
# @return [SortedSet] sorted_set of key.
|
23
|
+
def [](key)
|
24
|
+
RailsKvsDriver::Lists::List.new(@driver_instance, key)
|
25
|
+
end
|
26
|
+
|
27
|
+
# add new list.
|
28
|
+
# if key exists, delete old list.
|
29
|
+
#
|
30
|
+
# @param key [String] list key.
|
31
|
+
# @param values [Array<String>] array of values.
|
32
|
+
# @return [Array<String>] array of values.
|
33
|
+
def []=(key, values)
|
34
|
+
delete(key) if has_key?(key)
|
35
|
+
list = self[key]
|
36
|
+
values.each {|value| list.push_last(value) }
|
37
|
+
end
|
38
|
+
|
39
|
+
# delete list.
|
40
|
+
#
|
41
|
+
# @param key [String] key of list.
|
42
|
+
def delete(key)
|
43
|
+
@driver_instance.delete(key)
|
44
|
+
end
|
45
|
+
|
46
|
+
# get all list keys from kvs.
|
47
|
+
#
|
48
|
+
# @return [Array<String>] array of key names.
|
49
|
+
def keys
|
50
|
+
@driver_instance.get_list_keys
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module RailsKvsDriver
|
2
2
|
module SortedSets
|
3
3
|
class SortedSet
|
4
|
+
include Enumerable
|
5
|
+
|
4
6
|
attr_accessor :driver_instance
|
5
7
|
attr_accessor :key
|
6
8
|
|
@@ -38,7 +40,7 @@ module RailsKvsDriver
|
|
38
40
|
# @param reverse [Boolean] order by desc. (default=false(acs))
|
39
41
|
# @param limit [Integer] limit number to acquire at a time. (default=1000)
|
40
42
|
# @param &block [{|member, score, position| }] each the block of code for each member of sorted set.
|
41
|
-
def each(reverse=false, limit=1000)
|
43
|
+
def each(reverse = false, limit = 1000)
|
42
44
|
count = length
|
43
45
|
position = 0
|
44
46
|
|
@@ -66,6 +68,15 @@ module RailsKvsDriver
|
|
66
68
|
@driver_instance.increment_sorted_set(@key, member, score)
|
67
69
|
end
|
68
70
|
|
71
|
+
# decrement member's score of sorted set.
|
72
|
+
#
|
73
|
+
# @param member [String] member of sorted set.
|
74
|
+
# @param score [Float] decrement score
|
75
|
+
# @return [Float] score after decrement.
|
76
|
+
def decrement(member, score)
|
77
|
+
@driver_instance.increment_sorted_set(@key, member, score*-1)
|
78
|
+
end
|
79
|
+
|
69
80
|
# length of sorted_set
|
70
81
|
#
|
71
82
|
# @return [Integer] length of sorted_set
|
@@ -88,6 +99,7 @@ module RailsKvsDriver
|
|
88
99
|
@driver_instance.remove_sorted_set(@key, member)
|
89
100
|
end
|
90
101
|
|
102
|
+
alias size length
|
91
103
|
end
|
92
104
|
end
|
93
105
|
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
require 'rails_kvs_driver/sorted_sets/sorted_set'
|
2
|
+
require 'rails_kvs_driver/common_methods/listable'
|
2
3
|
|
3
4
|
module RailsKvsDriver
|
4
5
|
module SortedSets
|
5
6
|
class SortedSets
|
7
|
+
include RailsKvsDriver::CommonMethods::Listable
|
8
|
+
include Enumerable
|
9
|
+
|
6
10
|
attr_accessor :driver_instance
|
7
11
|
|
8
12
|
# initialize sorted_sets
|
@@ -28,7 +32,7 @@ module RailsKvsDriver
|
|
28
32
|
# @return [Array<Array<member,score>>] meber_sets
|
29
33
|
def []=(key, member_sets)
|
30
34
|
delete(key) if has_key?(key)
|
31
|
-
sorted_set =
|
35
|
+
sorted_set = self[key]
|
32
36
|
member_sets.each {|member_set| sorted_set[member_set[0]] = member_set[1]}
|
33
37
|
end
|
34
38
|
|
@@ -39,21 +43,6 @@ module RailsKvsDriver
|
|
39
43
|
@driver_instance.delete(key)
|
40
44
|
end
|
41
45
|
|
42
|
-
# execute the block of code for each sorted_set.
|
43
|
-
#
|
44
|
-
# @param &block [{|key| }] each the block of code for each key of sorted set.
|
45
|
-
def each
|
46
|
-
keys.each {|key| yield key }
|
47
|
-
end
|
48
|
-
|
49
|
-
# check key in sorted set.
|
50
|
-
#
|
51
|
-
# @param key [String] key name.
|
52
|
-
# @return [Boolean] result.
|
53
|
-
def has_key?(key)
|
54
|
-
keys.include?(key)
|
55
|
-
end
|
56
|
-
|
57
46
|
# get all keys from kvs.
|
58
47
|
#
|
59
48
|
# @return [Array<String>] array of key names.
|
@@ -61,13 +50,6 @@ module RailsKvsDriver
|
|
61
50
|
@driver_instance.get_sorted_set_keys
|
62
51
|
end
|
63
52
|
|
64
|
-
# get length of sorted_set.
|
65
|
-
#
|
66
|
-
# @return [Integer] length of keys.
|
67
|
-
def length
|
68
|
-
keys.length
|
69
|
-
end
|
70
|
-
|
71
53
|
end
|
72
54
|
end
|
73
55
|
end
|
data/lib/rails_kvs_driver.rb
CHANGED
@@ -72,6 +72,130 @@ module RailsKvsDriver
|
|
72
72
|
raise NoMethodError
|
73
73
|
end
|
74
74
|
|
75
|
+
|
76
|
+
|
77
|
+
#--------------------
|
78
|
+
# list (same as list of redis. refer to redis.)
|
79
|
+
#--------------------
|
80
|
+
|
81
|
+
# count value of the list.
|
82
|
+
# when the key doesn't exist, return 0.
|
83
|
+
#
|
84
|
+
# @param key [String] key of the list.
|
85
|
+
# @return [Integer] number.
|
86
|
+
# @abstract count value of the list.
|
87
|
+
def count_list_value(key)
|
88
|
+
raise NoMethodError
|
89
|
+
end
|
90
|
+
|
91
|
+
# delete value from list.
|
92
|
+
#
|
93
|
+
# @param key [String] key of the list.
|
94
|
+
# @param value [String] delete value.
|
95
|
+
# @abstract delete value from list.
|
96
|
+
def delete_list_value(key, value)
|
97
|
+
raise NoMethodError
|
98
|
+
end
|
99
|
+
|
100
|
+
# delete at index from list.
|
101
|
+
#
|
102
|
+
# @param key [String] key of the list.
|
103
|
+
# @param index [Integer] index of the list.
|
104
|
+
# @abstract delete at index from list.
|
105
|
+
def delete_list_value_at(key, index)
|
106
|
+
raise NoMethodError
|
107
|
+
end
|
108
|
+
|
109
|
+
# get all keys of existed list.
|
110
|
+
#
|
111
|
+
# @return [Array<String>] keys.
|
112
|
+
# @abstract get all keys of existed list.
|
113
|
+
def get_list_keys
|
114
|
+
raise NoMethodError
|
115
|
+
end
|
116
|
+
|
117
|
+
# get value from index of the list.
|
118
|
+
# when the key doesn't exist, return nil.
|
119
|
+
#
|
120
|
+
# @param key [String] key of the list.
|
121
|
+
# @param index [Integer] index of the list.
|
122
|
+
# @return [String] value.
|
123
|
+
# @abstract get value from index of the list.
|
124
|
+
def get_list_value(key, index)
|
125
|
+
raise NoMethodError
|
126
|
+
end
|
127
|
+
|
128
|
+
# get values from index of the list.
|
129
|
+
# @example get_list_value(:key) => get all.
|
130
|
+
# @example get_list_value(:key, 5, 10) => 5~10 return total 6 values.
|
131
|
+
#
|
132
|
+
# @param key [String] key of the list.
|
133
|
+
# @param start [Integer] start index of the list.
|
134
|
+
# @param stop [Integer] end index of the list.
|
135
|
+
# @return [Array<String>] value.
|
136
|
+
# @abstract get values from index of the list.
|
137
|
+
def get_list_values(key, start=0, stop=-1)
|
138
|
+
raise NoMethodError
|
139
|
+
end
|
140
|
+
|
141
|
+
# push value to first of the list.
|
142
|
+
# when the key doesn't exist, it's made newly list.
|
143
|
+
#
|
144
|
+
# @param key [String] key of list.
|
145
|
+
# @param value [String] push value.
|
146
|
+
# @return [Integer] length of list after push.
|
147
|
+
# @abstract push value to first of the list.
|
148
|
+
def push_list_first(key, value)
|
149
|
+
raise NoMethodError
|
150
|
+
end
|
151
|
+
|
152
|
+
# push value to last of the list.
|
153
|
+
# when the key doesn't exist, it's made newly list.
|
154
|
+
#
|
155
|
+
# @param key [String] key of list.
|
156
|
+
# @param value [String] push value.
|
157
|
+
# @return [Integer] length of list after push.
|
158
|
+
# @abstract push value to last of the list.
|
159
|
+
def push_list_last(key, value)
|
160
|
+
raise NoMethodError
|
161
|
+
end
|
162
|
+
|
163
|
+
# pop value from first of the list.
|
164
|
+
# when the key doesn't exist or is empty. return nil.
|
165
|
+
#
|
166
|
+
# @param key [String] key of the list.
|
167
|
+
# @return [String] value of the key.
|
168
|
+
# @abstract pop value from first of the list.
|
169
|
+
def pop_list_first(key)
|
170
|
+
raise NoMethodError
|
171
|
+
end
|
172
|
+
|
173
|
+
# pop value from first of the list.
|
174
|
+
# when the key doesn't exist or is empty. return nil.
|
175
|
+
#
|
176
|
+
# @param key [String] key of the list.
|
177
|
+
# @return [String] value of the key.
|
178
|
+
# @abstract pop value from last of the list.
|
179
|
+
def pop_list_last(key)
|
180
|
+
raise NoMethodError
|
181
|
+
end
|
182
|
+
|
183
|
+
# set value to index of the list.
|
184
|
+
#
|
185
|
+
# @param key [String] key of the list.
|
186
|
+
# @param index [Integer] index of the list.
|
187
|
+
# @param value [String] set value.
|
188
|
+
# @abstract set value to index of the list.
|
189
|
+
def set_list_value(key, index, value)
|
190
|
+
raise NoMethodError
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
#--------------------
|
196
|
+
# sorted set (same as sorted set of redis. refer to redis.)
|
197
|
+
#--------------------
|
198
|
+
|
75
199
|
# add sorted set to kvs.
|
76
200
|
# when the key doesn't exist, it's made newly.
|
77
201
|
# @note same as sorted set of redis. refer to redis.
|
data/spec/common_example.rb
CHANGED
@@ -191,120 +191,137 @@ shared_examples_for 'RailsKvsDriver example' do |driver_class, driver_config|
|
|
191
191
|
end
|
192
192
|
|
193
193
|
context 'sorted_sets' do
|
194
|
-
|
195
|
-
it 'call []' do
|
194
|
+
before(:each) do
|
196
195
|
driver_class::session(driver_config) do |kvs|
|
197
|
-
kvs.add_sorted_set('
|
198
|
-
kvs.add_sorted_set('
|
199
|
-
|
200
|
-
expect(kvs.sorted_sets['example'].length).to eq(2)
|
201
|
-
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)
|
202
198
|
end
|
203
199
|
end
|
204
200
|
|
205
|
-
it 'call []
|
201
|
+
it 'call []' do
|
206
202
|
driver_class::session(driver_config) do |kvs|
|
207
|
-
kvs.sorted_sets['
|
208
|
-
kvs.sorted_sets['example'] = ['element2', 1]
|
209
|
-
|
210
|
-
expect(kvs.sorted_sets['example'].length).to eq(2)
|
203
|
+
expect(kvs.sorted_sets['anime'].instance_of?(RailsKvsDriver::SortedSets::SortedSet)).to be_true
|
211
204
|
end
|
212
205
|
end
|
213
206
|
|
214
|
-
it 'call
|
207
|
+
it 'call []=' do
|
215
208
|
driver_class::session(driver_config) do |kvs|
|
216
|
-
kvs.add_sorted_set('example', 'element', 1)
|
217
|
-
kvs.add_sorted_set('example', 'element2', 1)
|
218
209
|
|
219
|
-
expect
|
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)
|
220
217
|
end
|
221
218
|
end
|
222
219
|
|
220
|
+
|
223
221
|
it 'call delete' do
|
224
222
|
driver_class::session(driver_config) do |kvs|
|
225
|
-
kvs.
|
226
|
-
kvs.add_sorted_set('example2', 'element2', 1)
|
227
|
-
|
228
|
-
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)
|
229
224
|
end
|
230
225
|
end
|
231
226
|
|
232
227
|
it 'call each' do
|
233
228
|
driver_class::session(driver_config) do |kvs|
|
234
|
-
kvs.add_sorted_set('example', 'element', 1)
|
235
|
-
kvs.add_sorted_set('example2', 'element2', 1)
|
236
|
-
|
237
229
|
kvs.sorted_sets.each do |key|
|
238
|
-
expect(
|
230
|
+
expect(key).to eq('anime')
|
239
231
|
end
|
240
232
|
end
|
241
233
|
end
|
242
234
|
|
243
|
-
it 'call
|
235
|
+
it 'call has_key?' do
|
244
236
|
driver_class::session(driver_config) do |kvs|
|
245
|
-
kvs.
|
246
|
-
kvs.
|
247
|
-
|
248
|
-
kvs.sorted_sets.each_member('example') do |member, score, position|
|
249
|
-
expect(kvs.sorted_sets['example', member]).to eq(score)
|
250
|
-
end
|
237
|
+
expect(kvs.sorted_sets.has_key?('anime')).to be_true
|
238
|
+
expect(kvs.sorted_sets.has_key?('nothing key')).to be_false
|
251
239
|
end
|
252
240
|
end
|
253
241
|
|
254
|
-
it 'call
|
242
|
+
it 'call keys' do
|
255
243
|
driver_class::session(driver_config) do |kvs|
|
256
|
-
kvs.
|
257
|
-
|
258
|
-
expect(kvs.sorted_sets.has_key?('example')).to be_true
|
259
|
-
expect(kvs.sorted_sets.has_key?('nothing key')).to be_false
|
244
|
+
expect(kvs.sorted_sets.keys.length).to eq(1)
|
260
245
|
end
|
261
246
|
end
|
262
247
|
|
263
|
-
it 'call
|
248
|
+
it 'call length' do
|
264
249
|
driver_class::session(driver_config) do |kvs|
|
265
|
-
kvs.
|
266
|
-
|
267
|
-
expect(kvs.sorted_sets.has_member?('example','element')).to be_true
|
268
|
-
expect(kvs.sorted_sets.has_member?('example','nothing member')).to be_false
|
269
|
-
expect(kvs.sorted_sets.has_member?('nothing key', 'element')).to be_false
|
250
|
+
expect(kvs.sorted_sets.length).to eq(1)
|
270
251
|
end
|
271
252
|
end
|
272
253
|
|
273
|
-
it 'call increment' do
|
274
|
-
driver_class::session(driver_config) do |kvs|
|
275
|
-
kvs.add_sorted_set('example', 'element', 10)
|
276
254
|
|
277
|
-
|
278
|
-
|
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
|
279
260
|
end
|
280
|
-
end
|
281
261
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
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
|
286
277
|
|
287
|
-
|
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
|
288
291
|
end
|
289
|
-
end
|
290
292
|
|
291
|
-
it 'call length' do
|
292
|
-
driver_class::session(driver_config) do |kvs|
|
293
|
-
kvs.add_sorted_set('example', 'element', 10)
|
294
|
-
kvs.add_sorted_set('example2', 'element', 1)
|
295
293
|
|
296
|
-
|
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
|
297
299
|
end
|
298
|
-
end
|
299
300
|
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
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
|
304
306
|
|
305
|
-
|
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
|
312
|
+
|
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
|
306
321
|
end
|
322
|
+
|
307
323
|
end
|
324
|
+
|
308
325
|
end
|
309
326
|
end
|
310
327
|
end
|
@@ -28,6 +28,10 @@ describe RailsKvsDriver::DefinedBaseMethod do
|
|
28
28
|
})
|
29
29
|
end
|
30
30
|
|
31
|
+
it 'call methods of Enumerable' do
|
32
|
+
expect(@instance.count).to eq(3)
|
33
|
+
end
|
34
|
+
|
31
35
|
it 'call each' do
|
32
36
|
count = 0
|
33
37
|
expect{
|
@@ -37,6 +41,10 @@ describe RailsKvsDriver::DefinedBaseMethod do
|
|
37
41
|
}.to change{count}.by(3)
|
38
42
|
end
|
39
43
|
|
44
|
+
it 'call empty?' do
|
45
|
+
expect(@instance.empty?).to be_false
|
46
|
+
end
|
47
|
+
|
40
48
|
it 'call has_key?' do
|
41
49
|
expect(@instance.has_key?(:a)).to be_true
|
42
50
|
end
|
@@ -44,5 +52,9 @@ describe RailsKvsDriver::DefinedBaseMethod do
|
|
44
52
|
it 'call length' do
|
45
53
|
expect(@instance.length).to eq(3)
|
46
54
|
end
|
55
|
+
|
56
|
+
it 'call size' do
|
57
|
+
expect(@instance.size).to eq(3)
|
58
|
+
end
|
47
59
|
end
|
48
60
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe RailsKvsDriver::Lists::List do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@driver = MockDriver.new(nil,nil)
|
8
|
+
@driver.stub({
|
9
|
+
count_list_value: 100,
|
10
|
+
delete: true,
|
11
|
+
delete_list_value: true,
|
12
|
+
delete_list_value_at: true,
|
13
|
+
get_list_keys: [:a,:b,:c],
|
14
|
+
get_list_value: 'Nyarukosan',
|
15
|
+
get_list_values: [:Nyarukosan],
|
16
|
+
push_list_first: 5,
|
17
|
+
push_list_last: 5,
|
18
|
+
pop_list_first: 'Nyarukosan',
|
19
|
+
pop_list_last: 'Nyarukosan',
|
20
|
+
set_list_value: ''
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'call []' do
|
25
|
+
expect((@driver.lists[:key][:list_key]).instance_of?(String)).to be_true
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'call []=' do
|
29
|
+
expect(@driver.lists[:key][:list_key] = 'hogehoge').to eq('hogehoge')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'call delete' do
|
33
|
+
expect(@driver.lists[:key].delete(:a)).to be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'call delete_at' do
|
37
|
+
expect(@driver.lists[:key].delete(1)).to be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'call each' do
|
41
|
+
count = 0
|
42
|
+
expect{
|
43
|
+
@driver.lists[:key].each do |key|
|
44
|
+
count += 1
|
45
|
+
end
|
46
|
+
}.to change{count}.by(100)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'call length' do
|
50
|
+
expect(@driver.lists[:key].length).to eq(100)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'call size' do
|
54
|
+
expect(@driver.lists[:key].size).to eq(100)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe RailsKvsDriver::Lists::Lists do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@driver = MockDriver.new(nil,nil)
|
8
|
+
@driver.stub({
|
9
|
+
count_list_value: 100,
|
10
|
+
delete: true,
|
11
|
+
delete_list_value: true,
|
12
|
+
delete_list_value_at: true,
|
13
|
+
get_list_keys: [:a,:b,:c],
|
14
|
+
get_list_value: 'Nyarukosan',
|
15
|
+
push_list_first: 5,
|
16
|
+
push_list_last: 5,
|
17
|
+
pop_list_first: 'Nyarukosan',
|
18
|
+
pop_list_last: 'Nyarukosan',
|
19
|
+
set_list_value: ''
|
20
|
+
})
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'call methods of Enumerable' do
|
24
|
+
expect(@driver.lists.count).to eq(3)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'call []' do
|
28
|
+
expect((@driver.lists[:key]).instance_of?(RailsKvsDriver::Lists::List)).to be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'call []=' do
|
32
|
+
sorted_set = [:a,:b,:c]
|
33
|
+
expect(@driver.lists[:key] = sorted_set).to eq(sorted_set)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'call delete' do
|
37
|
+
expect(@driver.lists.delete(:a)).to be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'call each' do
|
41
|
+
count = 0
|
42
|
+
expect{
|
43
|
+
@driver.lists.each do |key|
|
44
|
+
count += 1
|
45
|
+
end
|
46
|
+
}.to change{count}.by(3)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'call has_key?' do
|
50
|
+
expect(@driver.lists.has_key?(:a)).to be_true
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'call keys' do
|
54
|
+
expect(@driver.lists.keys.length).to eq(3)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'call length' do
|
58
|
+
expect(@driver.lists.length).to eq(3)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'call size' do
|
62
|
+
expect(@driver.lists.size).to eq(3)
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -17,12 +17,16 @@ describe RailsKvsDriver::SortedSets::SortedSet do
|
|
17
17
|
})
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'call methods of Enumerable' do
|
21
|
+
expect(@driver.sorted_sets[:key].count).to eq(100)
|
22
|
+
end
|
23
|
+
|
20
24
|
it 'call []' do
|
21
|
-
expect(@driver.sorted_sets[:key][:member]
|
25
|
+
expect(@driver.sorted_sets[:key][:member]).to eq(100)
|
22
26
|
end
|
23
27
|
|
24
28
|
it 'call []=' do
|
25
|
-
expect(@driver.sorted_sets[:key][:member]).to eq(
|
29
|
+
expect(@driver.sorted_sets[:key][:member] = 1).to eq(1)
|
26
30
|
end
|
27
31
|
|
28
32
|
it 'call length' do
|
@@ -47,6 +51,10 @@ describe RailsKvsDriver::SortedSets::SortedSet do
|
|
47
51
|
expect( @driver.sorted_sets[:key].increment(:b, 1) ).to eq(10)
|
48
52
|
end
|
49
53
|
|
54
|
+
it 'call decrement' do
|
55
|
+
expect( @driver.sorted_sets[:key].decrement(:b, 1) ).to eq(10)
|
56
|
+
end
|
57
|
+
|
50
58
|
it 'call length' do
|
51
59
|
expect(@driver.sorted_sets[:key].length).to eq(100)
|
52
60
|
end
|
@@ -58,4 +66,9 @@ describe RailsKvsDriver::SortedSets::SortedSet do
|
|
58
66
|
it 'call remove' do
|
59
67
|
expect(@driver.sorted_sets[:key].remove(:b)).to be_true
|
60
68
|
end
|
69
|
+
|
70
|
+
it 'call size' do
|
71
|
+
expect(@driver.sorted_sets[:key].size).to eq(100)
|
72
|
+
end
|
73
|
+
|
61
74
|
end
|
@@ -17,13 +17,17 @@ describe RailsKvsDriver::SortedSets::SortedSets do
|
|
17
17
|
})
|
18
18
|
end
|
19
19
|
|
20
|
+
it 'call methods of Enumerable' do
|
21
|
+
expect(@driver.sorted_sets.count).to eq(3)
|
22
|
+
end
|
23
|
+
|
20
24
|
it 'call []' do
|
21
|
-
|
22
|
-
expect(@driver.sorted_sets[:key] = sorted_set).to eq(sorted_set)
|
25
|
+
expect((@driver.sorted_sets[:key]).instance_of?(RailsKvsDriver::SortedSets::SortedSet)).to be_true
|
23
26
|
end
|
24
27
|
|
25
28
|
it 'call []=' do
|
26
|
-
|
29
|
+
sorted_set = [['member', 1],['member', 2]]
|
30
|
+
expect(@driver.sorted_sets[:key] = sorted_set).to eq(sorted_set)
|
27
31
|
end
|
28
32
|
|
29
33
|
it 'call delete' do
|
@@ -51,4 +55,8 @@ describe RailsKvsDriver::SortedSets::SortedSets do
|
|
51
55
|
expect(@driver.sorted_sets.length).to eq(3)
|
52
56
|
end
|
53
57
|
|
58
|
+
it 'call size' do
|
59
|
+
expect(@driver.sorted_sets.size).to eq(3)
|
60
|
+
end
|
61
|
+
|
54
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_kvs_driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,7 +94,10 @@ files:
|
|
94
94
|
- README.md
|
95
95
|
- Rakefile
|
96
96
|
- lib/rails_kvs_driver.rb
|
97
|
+
- lib/rails_kvs_driver/common_methods/listable.rb
|
97
98
|
- lib/rails_kvs_driver/defined_base_method.rb
|
99
|
+
- lib/rails_kvs_driver/lists/list.rb
|
100
|
+
- lib/rails_kvs_driver/lists/lists.rb
|
98
101
|
- lib/rails_kvs_driver/session.rb
|
99
102
|
- lib/rails_kvs_driver/sorted_sets/sorted_set.rb
|
100
103
|
- lib/rails_kvs_driver/sorted_sets/sorted_sets.rb
|
@@ -103,6 +106,8 @@ files:
|
|
103
106
|
- rails_kvs_driver.gemspec
|
104
107
|
- spec/common_example.rb
|
105
108
|
- spec/rails_kvs_driver/defined_base_method_spec.rb
|
109
|
+
- spec/rails_kvs_driver/lists/list_spec.rb
|
110
|
+
- spec/rails_kvs_driver/lists/lists_spec.rb
|
106
111
|
- spec/rails_kvs_driver/session_spec.rb
|
107
112
|
- spec/rails_kvs_driver/sorted_sets/sorted_set_spec.rb
|
108
113
|
- spec/rails_kvs_driver/sorted_sets/sorted_sets_spec.rb
|
@@ -137,6 +142,8 @@ summary: rails_kvs_driver is available to use namespace and connection pool and
|
|
137
142
|
test_files:
|
138
143
|
- spec/common_example.rb
|
139
144
|
- spec/rails_kvs_driver/defined_base_method_spec.rb
|
145
|
+
- spec/rails_kvs_driver/lists/list_spec.rb
|
146
|
+
- spec/rails_kvs_driver/lists/lists_spec.rb
|
140
147
|
- spec/rails_kvs_driver/session_spec.rb
|
141
148
|
- spec/rails_kvs_driver/sorted_sets/sorted_set_spec.rb
|
142
149
|
- spec/rails_kvs_driver/sorted_sets/sorted_sets_spec.rb
|