roma-client 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,221 @@
1
+ module Roma
2
+ module Client
3
+ module Plugin
4
+ module Alist
5
+
6
+ def alist_at(key, index)
7
+ ret = sender(:value_list_receiver, key, nil, "alist_at %s #{index}")
8
+ return nil if ret.length == 0
9
+ ret[0]
10
+ end
11
+
12
+ def alist_clear(key)
13
+ sender(:oneline_receiver, key, nil, "alist_clear %s")
14
+ end
15
+
16
+ def alist_delete(key, value)
17
+ value_validator(value)
18
+ sender(:oneline_receiver, key, value, "alist_delete %s #{value.length}")
19
+ end
20
+
21
+ def alist_delete_at(key, index)
22
+ sender(:oneline_receiver, key, nil, "alist_delete_at %s #{index}")
23
+ end
24
+
25
+ def alist_empty?(key)
26
+ sender(:oneline_receiver, key, nil, "alist_empty? %s")
27
+ end
28
+
29
+ def alist_first(key)
30
+ ret = sender(:value_list_receiver, key, nil, "alist_first %s")
31
+ return nil if ret.length == 0
32
+ ret[0]
33
+ end
34
+
35
+ def alist_gets(key, range=nil)
36
+ if range
37
+ ret = sender(:value_list_receiver, key, nil, "alist_gets %s #{range}")
38
+ else
39
+ ret = sender(:value_list_receiver, key, nil, "alist_gets %s")
40
+ end
41
+ return nil if ret.length == 0
42
+ ret[0] = ret[0].to_i
43
+ ret
44
+ end
45
+
46
+ def alist_gets_with_time(key, range=nil)
47
+ if range
48
+ ret = sender(:value_list_receiver, key, nil, "alist_gets_with_time %s #{range}")
49
+ else
50
+ ret = sender(:value_list_receiver, key, nil, "alist_gets_with_time %s")
51
+ end
52
+ return nil if ret.length == 0
53
+ ret[0] = ret[0].to_i
54
+ ret
55
+ end
56
+
57
+ def alist_include?(key, value)
58
+ sender(:oneline_receiver, key, value, "alist_include? %s #{value.length}")
59
+ end
60
+
61
+ def alist_index(key, value)
62
+ value_validator(value)
63
+ ret = sender(:oneline_receiver, key, value, "alist_index %s #{value.length}")
64
+ return ret.to_i if ret =~ /\d+/
65
+ return nil if ret=='nil'
66
+ ret
67
+ end
68
+
69
+ def alist_insert(key, index, value)
70
+ value_validator(value)
71
+ sender(:oneline_receiver, key, value, "alist_insert %s #{index} #{value.length}")
72
+ end
73
+
74
+ def alist_sized_insert(key, array_size, value)
75
+ sender(:oneline_receiver, key, value, "alist_sized_insert %s #{array_size} #{value.length}")
76
+ end
77
+
78
+ def alist_swap_and_insert(key, value)
79
+ sender(:oneline_receiver, key, value, "alist_swap_and_insert %s #{value.length}")
80
+ end
81
+
82
+ def alist_swap_and_sized_insert(key, array_size, value)
83
+ value_validator(value)
84
+ sender(:oneline_receiver, key, value, "alist_swap_and_sized_insert %s #{array_size} #{value.length}")
85
+ end
86
+
87
+ def alist_expired_swap_and_insert(key, expt, value)
88
+ value_validator(value)
89
+ sender(:oneline_receiver, key, value,
90
+ "alist_expired_swap_and_insert %s #{expt} #{value.length}")
91
+ end
92
+
93
+ def alist_expired_swap_and_sized_insert(key, expt, array_size, value)
94
+ value_validator(value)
95
+ sender(:oneline_receiver, key, value,
96
+ "alist_expired_swap_and_sized_insert %s #{expt} #{array_size} #{value.length}")
97
+ end
98
+
99
+ def alist_join(key, sep, range=nil)
100
+ if range
101
+ ret = sender(:value_list_receiver, key, sep, "alist_join %s #{sep.length} #{range}")
102
+ else
103
+ ret = sender(:value_list_receiver, key, sep, "alist_join %s #{sep.length}")
104
+ end
105
+ return nil if ret.length == 0
106
+ ret[0] = ret[0].to_i
107
+ ret
108
+ end
109
+
110
+ def alist_join_with_time(key, sep, range=nil)
111
+ if range
112
+ ret = sender(:value_list_receiver, key, sep,
113
+ "alist_join_with_time %s #{sep.length} #{range}")
114
+ else
115
+ ret = sender(:value_list_receiver, key, sep,
116
+ "alist_join_with_time %s #{sep.length}")
117
+ end
118
+ return nil if ret.length == 0
119
+ ret[0] = ret[0].to_i
120
+ ret
121
+ end
122
+
123
+ def alist_to_json(key, range=nil)
124
+ if range
125
+ ret = sender(:value_list_receiver, key, nil, "alist_to_json %s #{range}")
126
+ else
127
+ ret = sender(:value_list_receiver, key, nil, "alist_to_json %s")
128
+ end
129
+ return nil if ret.length == 0
130
+ ret[0]
131
+ end
132
+
133
+ def alist_last(key)
134
+ ret = sender(:value_list_receiver, key, nil, "alist_last %s")
135
+ return nil if ret.length == 0
136
+ ret[0]
137
+ end
138
+
139
+ def alist_length(key)
140
+ ret = sender(:oneline_receiver, key, nil, "alist_length %s")
141
+ return ret.to_i if ret =~ /\d+/
142
+ ret
143
+ end
144
+
145
+ def alist_pop(key)
146
+ ret = sender(:value_list_receiver, key, nil, "alist_pop %s")
147
+ return nil if ret.length == 0
148
+ ret[0]
149
+ end
150
+
151
+ def alist_push(key, value)
152
+ value_validator(value)
153
+ sender(:oneline_receiver, key, value, "alist_push %s #{value.length}")
154
+ end
155
+
156
+ def alist_sized_push(key, array_size, value)
157
+ value_validator(value)
158
+ sender(:oneline_receiver, key, value,
159
+ "alist_sized_push %s #{array_size} #{value.length}")
160
+ end
161
+
162
+ def alist_swap_and_push(key, value)
163
+ value_validator(value)
164
+ sender(:oneline_receiver, key, value, "alist_swap_and_push %s #{value.length}")
165
+ end
166
+
167
+ def alist_swap_and_sized_push(key, array_size, value)
168
+ value_validator(value)
169
+ sender(:oneline_receiver, key, value,
170
+ "alist_swap_and_sized_push %s #{array_size} #{value.length}")
171
+ end
172
+
173
+ def alist_expired_swap_and_push(key, expt, value)
174
+ value_validator(value)
175
+ sender(:oneline_receiver, key, value,
176
+ "alist_expired_swap_and_push %s #{expt} #{value.length}")
177
+ end
178
+
179
+ def alist_expired_swap_and_sized_push(key, expt, array_size, value)
180
+ value_validator(value)
181
+ sender(:oneline_receiver, key, value,
182
+ "alist_expired_swap_and_sized_push %s #{expt} #{array_size} #{value.length}")
183
+ end
184
+
185
+ def alist_update_at(key, index, value)
186
+ value_validator(value)
187
+ sender(:oneline_receiver, key, value,
188
+ "alist_update_at %s #{index} #{value.length}")
189
+ end
190
+
191
+ def alist_shift(key)
192
+ ret = sender(:value_list_receiver, key, nil, "alist_shift %s")
193
+ return nil if ret.length == 0
194
+ ret[0]
195
+ end
196
+
197
+ def alist_to_s(key, range=nil)
198
+ if range
199
+ ret = sender(:value_list_receiver, key, nil, "alist_to_s %s #{range}")
200
+ else
201
+ ret = sender(:value_list_receiver, key, nil, "alist_to_s %s")
202
+ end
203
+ return ret if ret.instance_of?(String)
204
+ return nil if ret.length == 0
205
+ ret[0] = ret[0].to_i
206
+ ret[1] = eval(ret[1])
207
+ ret
208
+ end
209
+
210
+ private
211
+
212
+ def value_validator(value)
213
+ if value == nil || !value.instance_of?(String)
214
+ raise "value must be a String object."
215
+ end
216
+ end
217
+
218
+ end # module Alist
219
+ end # module Plugin
220
+ end # module Client
221
+ end # module Roma
@@ -0,0 +1,96 @@
1
+ module Roma
2
+ module Client
3
+ module Plugin
4
+ module Map
5
+
6
+ def map_set(key, mapkey, value, expt = 0)
7
+ value_validator(value)
8
+ sender(:oneline_receiver, key, value, "map_set %s #{mapkey} 0 #{expt} #{value.length}")
9
+ end
10
+
11
+ def map_get(key, mapkey)
12
+ ret = sender(:value_list_receiver, key, nil, "map_get %s #{mapkey}")
13
+ return nil if ret==nil || ret.length == 0
14
+ ret[0]
15
+ end
16
+
17
+ def map_delete(key, mapkey)
18
+ sender(:oneline_receiver, key, nil, "map_delete %s #{mapkey}")
19
+ end
20
+
21
+ def map_clear(key)
22
+ sender(:oneline_receiver, key, nil, "map_clear %s")
23
+ end
24
+
25
+ def map_size(key)
26
+ ret = sender(:oneline_receiver, key, nil, "map_size %s")
27
+ return ret.to_i if ret =~ /\d+/
28
+ ret
29
+ end
30
+
31
+ def map_key?(key, mapkey)
32
+ ret = sender(:oneline_receiver, key, nil, "map_key? %s #{mapkey}")
33
+ if ret == 'true'
34
+ true
35
+ elsif ret == 'false'
36
+ false
37
+ else
38
+ ret
39
+ end
40
+ end
41
+
42
+ def map_value?(key, value)
43
+ value_validator(value)
44
+ ret = sender(:oneline_receiver, key, value, "map_value? %s #{value.length}")
45
+ if ret == 'true'
46
+ true
47
+ elsif ret == 'false'
48
+ false
49
+ else
50
+ ret
51
+ end
52
+ end
53
+
54
+ def map_empty?(key)
55
+ ret = sender(:oneline_receiver, key, nil, "map_empty? %s")
56
+ if ret == 'true'
57
+ true
58
+ elsif ret == 'false'
59
+ false
60
+ else
61
+ ret
62
+ end
63
+ end
64
+
65
+ def map_keys(key)
66
+ ret = sender(:value_list_receiver, key, nil, "map_keys %s")
67
+ return nil if ret.length == 0
68
+ ret[0] = ret[0].to_i
69
+ ret
70
+ end
71
+
72
+ def map_values(key)
73
+ ret = sender(:value_list_receiver, key, nil, "map_values %s")
74
+ return nil if ret.length == 0
75
+ ret[0] = ret[0].to_i
76
+ ret
77
+ end
78
+
79
+ def map_to_s(key)
80
+ ret = sender(:value_list_receiver, key, nil, "map_to_s %s")
81
+ return nil if ret.length == 0
82
+ ret[0]
83
+ end
84
+
85
+ private
86
+
87
+ def value_validator(value)
88
+ if value == nil || !value.instance_of?(String)
89
+ raise "value must be a String object."
90
+ end
91
+ end
92
+
93
+ end # module Map
94
+ end # module Plugin
95
+ end # module Client
96
+ end # module Roma
@@ -0,0 +1,126 @@
1
+ require 'json'
2
+ require 'time'
3
+
4
+ module Roma #:nodoc
5
+ module Client #:nodoc
6
+ module Plugin #:nodoc
7
+
8
+ # MapCount plugin module for ROMA client
9
+ module MapCount
10
+ # get mapcount (for JSON value)
11
+ #
12
+ # key:: key to get mapcount data
13
+ # sub_keys:: array to get mapcount data subkeys.
14
+ # subkey can't include "," and ":"
15
+ # return:: result values hash.
16
+ # If data is not set, return empty hash.
17
+ def mapcount_get(key, sub_keys = nil)
18
+ sub_keys_str = sub_keys_to_req_str(sub_keys)
19
+
20
+ ret = sender(:value_list_receiver, key, nil,
21
+ "mapcount_get %s 0 %d\r\n%s\r\n",
22
+ sub_keys_str.length, sub_keys_str)
23
+ convert_ret_to_result(ret, :json)
24
+ end
25
+
26
+ # get mapcount (for Marshal value)
27
+ #
28
+ # key:: key to get mapcount data
29
+ # sub_keys:: array to get mapcount data subkeys.
30
+ # subkey can't include "," and ":"
31
+ # return:: result values hash.
32
+ # If data is not set, return empty hash.
33
+ def mapcount_get_ms(key, sub_keys = nil)
34
+ sub_keys_str = sub_keys_to_req_str(sub_keys)
35
+
36
+ ret = sender(:value_list_receiver, key, nil,
37
+ "mapcount_get_ms %s 0 %d\r\n%s\r\n",
38
+ sub_keys_str.length, sub_keys_str)
39
+ convert_ret_to_result(ret, :marshal)
40
+ end
41
+
42
+ # countup (for JSON value)
43
+ #
44
+ # key:: key to count up data
45
+ # sub_keys:: sub keys to count up.
46
+ # You can set String 'sk',
47
+ # or Array ['sk1','sk2','sk3'],
48
+ # or Hash {'sk1' => 1, 'sk2' => 3} .
49
+ # expt:: expire seconds. This param format is same as RomaClient.set .
50
+ # return:: result values. It is Marshal format string.
51
+ def mapcount_countup(key, sub_keys, expt = 0)
52
+ sub_keys_str = sub_keys_to_req_str(sub_keys)
53
+ ret = sender(:value_list_receiver, key, nil,
54
+ "mapcount_countup %s %d %d\r\n%s\r\n",
55
+ expt.to_i, sub_keys_str.length, sub_keys_str)
56
+ convert_ret_to_result(ret, :json)
57
+ end
58
+
59
+ # countup (for Marshal value)
60
+ #
61
+ # key:: key to count up data
62
+ # sub_keys:: sub keys to count up.
63
+ # You can set String 'sk',
64
+ # or Array ['sk1','sk2','sk3'],
65
+ # or Hash {'sk1' => 1, 'sk2' => 3} .
66
+ # expt:: expire seconds. This param format is same as RomaClient.set .
67
+ # return:: result values. It is Marshal format string.
68
+ def mapcount_countup_ms(key, sub_keys, expt = 0)
69
+ sub_keys_str = sub_keys_to_req_str(sub_keys)
70
+ ret = sender(:value_list_receiver, key, nil,
71
+ "mapcount_countup_ms %s %d %d\r\n%s\r\n",
72
+ expt.to_i, sub_keys_str.length, sub_keys_str)
73
+ convert_ret_to_result(ret, :marshal)
74
+ end
75
+
76
+ # update key expire (for JSON value)
77
+ def mapcount_update(key, sub_keys = nil, expt = 0)
78
+ sub_keys_str = sub_keys_to_req_str(sub_keys)
79
+ ret = sender(:value_list_receiver, key, nil,
80
+ "mapcount_update %s %d %d\r\n%s\r\n",
81
+ expt.to_i, sub_keys_str.length, sub_keys_str)
82
+ convert_ret_to_result(ret, :json)
83
+ end
84
+
85
+ # update key expire (for Marshal value)
86
+ def mapcount_update_ms(key, sub_keys = nil, expt = 0)
87
+ sub_keys_str = sub_keys_to_req_str(sub_keys)
88
+ ret = sender(:value_list_receiver, key, nil,
89
+ "mapcount_update_ms %s %d %d\r\n%s\r\n",
90
+ expt.to_i, sub_keys_str.length, sub_keys_str)
91
+ convert_ret_to_result(ret, :marshal)
92
+ end
93
+
94
+ private
95
+ def convert_ret_to_result(ret, stype)
96
+ if ret.empty?
97
+ return nil
98
+ end
99
+
100
+ if stype == :marshal
101
+ res = Marshal.load(ret[0])
102
+ else
103
+ res = JSON.parse(ret[0])
104
+ end
105
+
106
+ if res["last_updated_date"]
107
+ res["last_updated_date"] = Time.parse(res["last_updated_date"])
108
+ end
109
+ res
110
+ end
111
+
112
+ def sub_keys_to_req_str(sub_keys)
113
+ sub_keys_str = ''
114
+ if sub_keys.is_a?(String)
115
+ sub_keys_str = sub_keys
116
+ elsif sub_keys.is_a?(Array)
117
+ sub_keys_str = sub_keys.join(',')
118
+ elsif sub_keys.is_a?(Hash)
119
+ sub_keys_str = sub_keys.map{|k,v| "#{k}:#{v}"}.join(",")
120
+ end
121
+ sub_keys_str
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -6,19 +6,15 @@
6
6
  module Roma #:nodoc:
7
7
  module Client #:nodoc:
8
8
  # == What Is This Library?
9
- # ROMA クライアントバージョン情報モジュール
9
+ # ROMA client version info.
10
10
  #
11
11
  module VERSION
12
- # メジャーバージョン
13
12
  MAJOR = 0
14
13
 
15
- # マイナバージョン
16
14
  MINOR = 4
17
15
 
18
- # TINY version
19
- TINY = 0
16
+ TINY = 1
20
17
 
21
- # バージョン文字列
22
18
  STRING = [MAJOR, MINOR, TINY].join('.')
23
19
  end
24
20
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roma-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Muga Nishizawa
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-12-21 00:00:00 Z
19
+ date: 2012-02-20 00:00:00 Z
20
20
  dependencies: []
21
21
 
22
22
  description: " ROMA client library\n"
@@ -47,6 +47,9 @@ files:
47
47
  - lib/roma/client/client_pool.rb
48
48
  - lib/roma/client/routing/routing_data.rb
49
49
  - lib/roma/client/sender.rb
50
+ - lib/roma/client/plugin/map.rb
51
+ - lib/roma/client/plugin/mapcount.rb
52
+ - lib/roma/client/plugin/alist.rb
50
53
  - lib/roma/client/rclient.rb
51
54
  - lib/roma/client/client_rttable.rb
52
55
  - lib/roma/client/tools/showbalance.rb