couchbase-jruby-client 0.2.2-java → 1.0.4-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +103 -0
- data/.ruby-version +1 -1
- data/Rakefile +13 -2
- data/couchbase-jruby-client.gemspec +7 -6
- data/lib/couchbase/bucket.rb +11 -338
- data/lib/couchbase/cluster.rb +10 -88
- data/lib/couchbase/configuration.rb +39 -0
- data/lib/couchbase/design_doc.rb +18 -73
- data/lib/couchbase/document.rb +34 -0
- data/lib/couchbase/error.rb +0 -35
- data/lib/couchbase/operations.rb +60 -40
- data/lib/couchbase/version.rb +1 -1
- data/lib/couchbase/view.rb +55 -345
- data/lib/couchbase.rb +37 -141
- data/lib/jars/couchbase-core-io-1.1.4.jar +0 -0
- data/lib/jars/couchbase-java-client-2.1.4.jar +0 -0
- data/lib/jars/rxjava-1.0.8.jar +0 -0
- data/lib/jars/rxjruby-0.0.1.jar +0 -0
- data/test/{test_cas.rb → helper.rb} +15 -10
- data/test/test_bucket.rb +14 -228
- data/test/test_cluster.rb +1 -29
- data/test/test_configuration.rb +51 -0
- data/test/test_couchbase.rb +28 -28
- data/test/test_design_doc.rb +29 -0
- data/test/test_document.rb +51 -0
- data/test/test_operations.rb +49 -0
- data/test/test_view.rb +62 -116
- metadata +43 -125
- data/lib/couchbase/async/callback.rb +0 -38
- data/lib/couchbase/async/queue.rb +0 -26
- data/lib/couchbase/async.rb +0 -32
- data/lib/couchbase/constants.rb +0 -29
- data/lib/couchbase/operations/arithmetic.rb +0 -290
- data/lib/couchbase/operations/delete.rb +0 -115
- data/lib/couchbase/operations/design_docs.rb +0 -99
- data/lib/couchbase/operations/fetch.rb +0 -33
- data/lib/couchbase/operations/get.rb +0 -303
- data/lib/couchbase/operations/stats.rb +0 -42
- data/lib/couchbase/operations/store.rb +0 -463
- data/lib/couchbase/operations/touch.rb +0 -140
- data/lib/couchbase/operations/unlock.rb +0 -209
- data/lib/couchbase/operations/utils.rb +0 -68
- data/lib/couchbase/query.rb +0 -76
- data/lib/couchbase/result.rb +0 -60
- data/lib/couchbase/transcoder.rb +0 -81
- data/lib/couchbase/utils.rb +0 -62
- data/lib/couchbase/view_row.rb +0 -227
- data/lib/jars/commons-codec-1.5.jar +0 -0
- data/lib/jars/couchbase-client-1.3.2-javadoc.jar +0 -0
- data/lib/jars/couchbase-client-1.3.2-sources.jar +0 -0
- data/lib/jars/couchbase-client-1.3.2.jar +0 -0
- data/lib/jars/httpcore-4.3.1.jar +0 -0
- data/lib/jars/httpcore-nio-4.3.1.jar +0 -0
- data/lib/jars/jettison-1.1.jar +0 -0
- data/lib/jars/netty-3.5.5.Final.jar +0 -0
- data/lib/jars/spymemcached-2.10.5-javadoc.jar +0 -0
- data/lib/jars/spymemcached-2.10.5-sources.jar +0 -0
- data/lib/jars/spymemcached-2.10.5.jar +0 -0
- data/tasks/benchmark.rake +0 -6
- data/tasks/test.rake +0 -36
- data/tasks/util.rake +0 -21
- data/test/mock.rb +0 -85
- data/test/profile/.gitignore +0 -1
- data/test/profile/.jrubyrc +0 -722
- data/test/profile/Gemfile +0 -7
- data/test/profile/benchmark.rb +0 -177
- data/test/profile/profile.rb +0 -59
- data/test/setup.rb +0 -74
- data/test/test_arithmetic.rb +0 -155
- data/test/test_async.rb +0 -24
- data/test/test_couchbase_rails_cache_store.rb +0 -341
- data/test/test_delete.rb +0 -139
- data/test/test_design_docs.rb +0 -67
- data/test/test_errors.rb +0 -74
- data/test/test_fetch.rb +0 -71
- data/test/test_format.rb +0 -142
- data/test/test_get.rb +0 -363
- data/test/test_query.rb +0 -23
- data/test/test_result.rb +0 -15
- data/test/test_stats.rb +0 -44
- data/test/test_store.rb +0 -203
- data/test/test_touch.rb +0 -90
- data/test/test_unlock.rb +0 -89
- data/test/test_utils.rb +0 -67
- data/test/test_version.rb +0 -28
- data/test/test_view_row.rb +0 -74
@@ -1,303 +0,0 @@
|
|
1
|
-
# Author:: Mike Evans <mike@urlgonomics.com>
|
2
|
-
# Copyright:: 2013 Urlgonomics LLC.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
module Couchbase::Operations
|
19
|
-
module Get
|
20
|
-
|
21
|
-
# Obtain an object stored in Couchbase by given key.
|
22
|
-
#
|
23
|
-
# @since 1.0.0
|
24
|
-
#
|
25
|
-
# @see http://couchbase.com/docs/couchbase-manual-2.0/couchbase-architecture-apis-memcached-protocol-additions.html#couchbase-architecture-apis-memcached-protocol-additions-getl
|
26
|
-
#
|
27
|
-
# @overload get(*keys, options = {})
|
28
|
-
# @param keys [String, Symbol, Array] One or several keys to fetch
|
29
|
-
# @param options [Hash] Options for operation.
|
30
|
-
# @option options [true, false] :extended (false) If set to +true+, the
|
31
|
-
# operation will return a tuple +[value, flags, cas]+, otherwise (by
|
32
|
-
# default) it returns just the value.
|
33
|
-
# @option options [Fixnum] :ttl (self.default_ttl) Expiry time for key.
|
34
|
-
# Values larger than 30*24*60*60 seconds (30 days) are interpreted as
|
35
|
-
# absolute times (from the epoch).
|
36
|
-
# @option options [true, false] :quiet (self.quiet) If set to +true+, the
|
37
|
-
# operation won't raise error for missing key, it will return +nil+.
|
38
|
-
# Otherwise it will raise error in synchronous mode. In asynchronous
|
39
|
-
# mode this option ignored.
|
40
|
-
# @option options [Symbol] :format (nil) Explicitly choose the decoder
|
41
|
-
# for this key (+:plain+, +:document+, +:marshal+). See
|
42
|
-
# {Bucket#default_format}.
|
43
|
-
# @option options [Fixnum, Boolean] :lock Lock the keys for time span.
|
44
|
-
# If this parameter is +true+ the key(s) will be locked for default
|
45
|
-
# timeout. Also you can use number to setup your own timeout in
|
46
|
-
# seconds. If it will be lower that zero or exceed the maximum, the
|
47
|
-
# server will use default value. You can determine actual default and
|
48
|
-
# maximum values calling {Bucket#stats} without arguments and
|
49
|
-
# inspecting keys "ep_getl_default_timeout" and "ep_getl_max_timeout"
|
50
|
-
# correspondingly. See overloaded hash syntax to specify custom timeout
|
51
|
-
# per each key.
|
52
|
-
# @option options [true, false] :assemble_hash (false) Assemble Hash for
|
53
|
-
# results. Hash assembled automatically if +:extended+ option is true
|
54
|
-
# or in case of "get and touch" multimple keys.
|
55
|
-
# @option options [true, false] :replica (false) Read key from replica
|
56
|
-
# node. Options +:ttl+ and +:lock+ are not compatible with +:replica+.
|
57
|
-
#
|
58
|
-
# @yieldparam ret [Result] the result of operation in asynchronous mode
|
59
|
-
# (valid attributes: +error+, +operation+, +key+, +value+, +flags+,
|
60
|
-
# +cas+).
|
61
|
-
#
|
62
|
-
# @return [Object, Array, Hash] the value(s) (or tuples in extended mode)
|
63
|
-
# associated with the key.
|
64
|
-
#
|
65
|
-
# @raise [Couchbase::Error::NotFound] if the key is missing in the
|
66
|
-
# bucket.
|
67
|
-
#
|
68
|
-
# @raise [Couchbase::Error::Connect] if connection closed (see {Bucket#reconnect})
|
69
|
-
#
|
70
|
-
# @raise [ArgumentError] when passing the block in synchronous mode
|
71
|
-
#
|
72
|
-
# @example Get single value in quiet mode (the default)
|
73
|
-
# c.get("foo") #=> the associated value or nil
|
74
|
-
#
|
75
|
-
# @example Use alternative hash-like syntax
|
76
|
-
# c["foo"] #=> the associated value or nil
|
77
|
-
#
|
78
|
-
# @example Get single value in verbose mode
|
79
|
-
# c.get("missing-foo", :quiet => false) #=> raises Couchbase::NotFound
|
80
|
-
# c.get("missing-foo", :quiet => true) #=> returns nil
|
81
|
-
#
|
82
|
-
# @example Get and touch single value. The key won't be accessible after 10 seconds
|
83
|
-
# c.get("foo", :ttl => 10)
|
84
|
-
#
|
85
|
-
# @example Extended get
|
86
|
-
# val, flags, cas = c.get("foo", :extended => true)
|
87
|
-
#
|
88
|
-
# @example Get multiple keys
|
89
|
-
# c.get("foo", "bar", "baz") #=> [val1, val2, val3]
|
90
|
-
#
|
91
|
-
# @example Get multiple keys with assembing result into the Hash
|
92
|
-
# c.get("foo", "bar", "baz", :assemble_hash => true)
|
93
|
-
# #=> {"foo" => val1, "bar" => val2, "baz" => val3}
|
94
|
-
#
|
95
|
-
# @example Extended get multiple keys
|
96
|
-
# c.get("foo", "bar", :extended => true)
|
97
|
-
# #=> {"foo" => [val1, flags1, cas1], "bar" => [val2, flags2, cas2]}
|
98
|
-
#
|
99
|
-
# @example Asynchronous get
|
100
|
-
# c.run do
|
101
|
-
# c.get("foo", "bar", "baz") do |res|
|
102
|
-
# ret.operation #=> :get
|
103
|
-
# ret.success? #=> true
|
104
|
-
# ret.key #=> "foo", "bar" or "baz" in separate calls
|
105
|
-
# ret.value
|
106
|
-
# ret.flags
|
107
|
-
# ret.cas
|
108
|
-
# end
|
109
|
-
# end
|
110
|
-
#
|
111
|
-
# @example Get and lock key using default timeout
|
112
|
-
# c.get("foo", :lock => true)
|
113
|
-
#
|
114
|
-
# @example Determine lock timeout parameters
|
115
|
-
# c.stats.values_at("ep_getl_default_timeout", "ep_getl_max_timeout")
|
116
|
-
# #=> [{"127.0.0.1:11210"=>"15"}, {"127.0.0.1:11210"=>"30"}]
|
117
|
-
#
|
118
|
-
# @example Get and lock key using custom timeout
|
119
|
-
# c.get("foo", :lock => 3)
|
120
|
-
#
|
121
|
-
# @example Get and lock multiple keys using custom timeout
|
122
|
-
# c.get("foo", "bar", :lock => 3)
|
123
|
-
#
|
124
|
-
# @overload get(keys, options = {})
|
125
|
-
# When the method receive hash map, it will behave like it receive list
|
126
|
-
# of keys (+keys.keys+), but also touch each key setting expiry time to
|
127
|
-
# the corresponding value. But unlike usual get this command always
|
128
|
-
# return hash map +{key => value}+ or +{key => [value, flags, cas]}+.
|
129
|
-
#
|
130
|
-
# @param keys [Hash] Map key-ttl
|
131
|
-
# @param options [Hash] Options for operation. (see options definition
|
132
|
-
# above)
|
133
|
-
#
|
134
|
-
# @return [Hash] the values (or tuples in extended mode) associated with
|
135
|
-
# the keys.
|
136
|
-
#
|
137
|
-
# @example Get and touch multiple keys
|
138
|
-
# c.get("foo" => 10, "bar" => 20) #=> {"foo" => val1, "bar" => val2}
|
139
|
-
#
|
140
|
-
# @example Extended get and touch multiple keys
|
141
|
-
# c.get({"foo" => 10, "bar" => 20}, :extended => true)
|
142
|
-
# #=> {"foo" => [val1, flags1, cas1], "bar" => [val2, flags2, cas2]}
|
143
|
-
#
|
144
|
-
# @example Get and lock multiple keys for chosen period in seconds
|
145
|
-
# c.get("foo" => 10, "bar" => 20, :lock => true)
|
146
|
-
# #=> {"foo" => val1, "bar" => val2}
|
147
|
-
#
|
148
|
-
def get(*args, &block)
|
149
|
-
key, options = expand_get_args(args)
|
150
|
-
get_key(key, options)
|
151
|
-
end
|
152
|
-
|
153
|
-
def [](key, options = {})
|
154
|
-
get(key, options)
|
155
|
-
end
|
156
|
-
|
157
|
-
def get_bulk(keys, options)
|
158
|
-
keys = keys.map { |key| validate_key(key) }
|
159
|
-
results = if options[:extended]
|
160
|
-
get_bulk_extended(keys, options)
|
161
|
-
else
|
162
|
-
client_get_bulk(keys)
|
163
|
-
end
|
164
|
-
|
165
|
-
not_found_error(results.size != keys.size, options)
|
166
|
-
|
167
|
-
if options[:assemble_hash] || options[:extended]
|
168
|
-
results
|
169
|
-
else
|
170
|
-
ordered_multi_values(keys, results)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def async_get(key, &block)
|
175
|
-
fail ArgumentError, 'Must pass a block to #async_get' unless block_given?
|
176
|
-
|
177
|
-
case key
|
178
|
-
when String, Symbol
|
179
|
-
key = validate_key(key)
|
180
|
-
meta = { op: :get, key: key }
|
181
|
-
future = client.asyncGet(key)
|
182
|
-
when Array
|
183
|
-
keys = key.map { |key| validate_key(key) }
|
184
|
-
meta = { op: :get }
|
185
|
-
future = client.asyncGetBulk(keys)
|
186
|
-
when Hash
|
187
|
-
# async_get_and_touch(key, options, &block)
|
188
|
-
end
|
189
|
-
register_future(future, meta, &block)
|
190
|
-
end
|
191
|
-
|
192
|
-
private
|
193
|
-
|
194
|
-
def get_key(key, options)
|
195
|
-
case key
|
196
|
-
when String, Symbol
|
197
|
-
get_single(key, options)
|
198
|
-
when Array
|
199
|
-
get_bulk(key, options)
|
200
|
-
when Hash
|
201
|
-
get_and_touch(key, options)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
def expand_get_args(args)
|
206
|
-
options = extract_options_hash(args)
|
207
|
-
key = args.size == 1 ? args.first : args
|
208
|
-
|
209
|
-
[validate_key(key), options]
|
210
|
-
end
|
211
|
-
|
212
|
-
def get_single(key, options)
|
213
|
-
if options[:lock]
|
214
|
-
client_get_and_lock(key, options)
|
215
|
-
elsif options[:extended]
|
216
|
-
get_extended(key, options)
|
217
|
-
else
|
218
|
-
value = if options.key?(:ttl)
|
219
|
-
client_get_and_touch(key, options[:ttl])
|
220
|
-
elsif options[:format]
|
221
|
-
client.get(key, transcoders[options[:format]])
|
222
|
-
else
|
223
|
-
client.get(key)
|
224
|
-
end
|
225
|
-
|
226
|
-
not_found_error(value.nil?, options)
|
227
|
-
value.nil? ? nil : value
|
228
|
-
end
|
229
|
-
rescue Java::JavaLang::RuntimeException
|
230
|
-
get_single(key, options.merge(format: :plain))
|
231
|
-
end
|
232
|
-
|
233
|
-
def get_extended(key, options = {})
|
234
|
-
if options.key?(:lock)
|
235
|
-
client_get_and_lock(key, options[:lock])
|
236
|
-
end
|
237
|
-
extended = client_get_extended(key)
|
238
|
-
not_found_error(extended.nil?, options)
|
239
|
-
extended
|
240
|
-
end
|
241
|
-
|
242
|
-
def get_and_touch(key, options = {})
|
243
|
-
if key.size > 1
|
244
|
-
get_bulk_and_touch(key, options)
|
245
|
-
else
|
246
|
-
key, ttl = key.first
|
247
|
-
value = client_get_and_touch(key, ttl)
|
248
|
-
not_found_error(value.nil?)
|
249
|
-
{ key => value }
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
def get_bulk_and_touch(keys, options = {})
|
254
|
-
options.merge!(assemble_hash: true)
|
255
|
-
results = get_bulk(keys.keys, options)
|
256
|
-
touch(keys)
|
257
|
-
results.to_hash
|
258
|
-
end
|
259
|
-
|
260
|
-
def get_bulk_extended(keys, options = {})
|
261
|
-
{}.tap do |results|
|
262
|
-
keys.each do |key|
|
263
|
-
result = get_extended(key, options)
|
264
|
-
results[key] = result unless result.nil?
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
def ordered_multi_values(keys, results)
|
270
|
-
keys.map { |key| results[key] }
|
271
|
-
end
|
272
|
-
|
273
|
-
def client_get_and_touch(key, ttl)
|
274
|
-
client.getAndTouch(key, ttl).getValue
|
275
|
-
end
|
276
|
-
|
277
|
-
def client_get_and_lock(key, options)
|
278
|
-
lock = options[:lock] == true ? 30 : options[:lock]
|
279
|
-
cas = client.getAndLock(key, lock)
|
280
|
-
if options[:extended]
|
281
|
-
[cas.getValue, nil, cas.getCas]
|
282
|
-
else
|
283
|
-
cas.getValue
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
def client_get_extended(key)
|
288
|
-
cas_value = client.gets(key)
|
289
|
-
|
290
|
-
if cas_value.nil?
|
291
|
-
nil
|
292
|
-
else
|
293
|
-
[cas_value.getValue, nil, cas_value.getCas]
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
def client_get_bulk(keys)
|
298
|
-
client.getBulk(keys)
|
299
|
-
rescue java.lang.ClassCastException
|
300
|
-
raise TypeError.new
|
301
|
-
end
|
302
|
-
end
|
303
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# Author:: Mike Evans <mike@urlgonomics.com>
|
2
|
-
# Copyright:: 2013 Urlgonomics LLC.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
module Couchbase::Operations
|
19
|
-
module Stats
|
20
|
-
|
21
|
-
def stats(statname = nil)
|
22
|
-
stats = if statname.nil?
|
23
|
-
client.getStats
|
24
|
-
else
|
25
|
-
client.getStats(statname)
|
26
|
-
end
|
27
|
-
|
28
|
-
stats = stats.to_hash
|
29
|
-
|
30
|
-
{}.tap do |hash|
|
31
|
-
stats.each_pair do |node, values|
|
32
|
-
node_value = node.to_s
|
33
|
-
values.each_pair do |stat, value|
|
34
|
-
hash[stat] ||= {}
|
35
|
-
hash[stat][node_value] = value
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|