couchbase-jruby-client 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -85
- data/lib/couchbase/async.rb +17 -0
- data/lib/couchbase/bucket.rb +19 -0
- data/lib/couchbase/constants.rb +17 -0
- data/lib/couchbase/design_doc.rb +18 -1
- data/lib/couchbase/error.rb +16 -0
- data/lib/couchbase/operations/arithmetic.rb +17 -0
- data/lib/couchbase/operations/delete.rb +17 -0
- data/lib/couchbase/operations/get.rb +37 -15
- data/lib/couchbase/operations/stats.rb +17 -0
- data/lib/couchbase/operations/store.rb +59 -35
- data/lib/couchbase/operations/touch.rb +17 -0
- data/lib/couchbase/operations/unlock.rb +17 -0
- data/lib/couchbase/operations/utils.rb +17 -0
- data/lib/couchbase/operations.rb +17 -0
- data/lib/couchbase/query.rb +20 -2
- data/lib/couchbase/result.rb +17 -0
- data/lib/couchbase/transcoder.rb +2 -2
- data/lib/couchbase/version.rb +18 -1
- data/lib/couchbase.rb +17 -1
- data/test/profile/benchmark.rb +63 -54
- data/test/test_bucket.rb +6 -0
- data/test/test_couchbase.rb +7 -0
- data/test/test_get.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cec53577bf9d3e2636d2b23c743e3ac1e3b28c6
|
4
|
+
data.tar.gz: e9ea82a72e30c618b76245bf4489f179bd45691e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed49ef81b60faadd9542d19f747eb1cd5ed9a8eb8527be7669b976edfb744888144523bbd6d7744d4273628976c20a25f84f6f6a1a85666f603007144418f65d
|
7
|
+
data.tar.gz: 0b4dfb1870cebcd69f8e5d9ddd74768b28e9ec4d75a9bf7a6820490eb566522f3d0b333175354447b199540f104443db7507b8fb5dc3c31905dd46fc0b19f44a
|
data/README.md
CHANGED
@@ -21,12 +21,15 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
Please consider this project a very incomplete "alpha" version at best. I'm getting close
|
23
23
|
to full coverage, though there are still some missing features. In fact, as I've gotten
|
24
|
-
more familiar with the differences between the native ruby api and the java, there are
|
24
|
+
more familiar with the differences between the native ruby api and the java, there are
|
25
25
|
definitely some features that don't make sense to implement.
|
26
26
|
|
27
27
|
Ultimately hoping to get to 100% support of the couchbase-ruby-model gem.
|
28
28
|
|
29
|
-
## Usage
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
See https://github.com/couchbase/couchbase-ruby-client for usage instructions as
|
32
|
+
they are largely the same. Important bits copied below:
|
30
33
|
|
31
34
|
First of all you need to load library:
|
32
35
|
|
@@ -67,89 +70,6 @@ connection options via `Couchbase.connection_options`:
|
|
67
70
|
Couchbase.bucket.name #=> "blog"
|
68
71
|
Couchbase.bucket.set("foo", "bar") #=> 3289400178357895424
|
69
72
|
|
70
|
-
The library supports both synchronous and asynchronous mode. In
|
71
|
-
asynchronous mode all operations will return control to caller
|
72
|
-
without blocking current thread. You can pass the block to method and it
|
73
|
-
will be called with result when the operation will be completed. You
|
74
|
-
need to run event loop when you scheduled your operations:
|
75
|
-
|
76
|
-
c = Couchbase.connect
|
77
|
-
c.run do |conn|
|
78
|
-
conn.get("foo") {|ret| puts ret.value}
|
79
|
-
conn.set("bar", "baz")
|
80
|
-
end
|
81
|
-
|
82
|
-
The handlers could be nested
|
83
|
-
|
84
|
-
c.run do |conn|
|
85
|
-
conn.get("foo") do |ret|
|
86
|
-
conn.incr(ret.value, :initial => 0)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
The asynchronous callback receives instance of `Couchbase::Result` which
|
91
|
-
responds to several methods to figure out what was happened:
|
92
|
-
|
93
|
-
* `success?`. Returns `true` if operation succed.
|
94
|
-
|
95
|
-
* `error`. Returns `nil` or exception object (subclass of
|
96
|
-
`Couchbase::Error::Base`) if something went wrong.
|
97
|
-
|
98
|
-
* `key`
|
99
|
-
|
100
|
-
* `value`
|
101
|
-
|
102
|
-
* `flags`
|
103
|
-
|
104
|
-
* `cas`. The CAS version tag.
|
105
|
-
|
106
|
-
* `node`. Node address. It is used in flush and stats commands.
|
107
|
-
|
108
|
-
* `operation`. The symbol, representing an operation.
|
109
|
-
|
110
|
-
|
111
|
-
To handle global errors in async mode `#on_error` callback should be
|
112
|
-
used. It can be set in following fashions:
|
113
|
-
|
114
|
-
c.on_error do |opcode, key, exc|
|
115
|
-
# ...
|
116
|
-
end
|
117
|
-
|
118
|
-
handler = lambda {|opcode, key, exc| }
|
119
|
-
c.on_error = handler
|
120
|
-
|
121
|
-
By default connection uses `:quiet` mode. This mean it won't raise
|
122
|
-
exceptions when the given key is not exists:
|
123
|
-
|
124
|
-
c.get("missing-key") #=> nil
|
125
|
-
|
126
|
-
It could be useful when you are trying to make you code a bit efficient
|
127
|
-
by avoiding exception handling. (See `#add` and `#replace` operations).
|
128
|
-
You can turn on these exception by passing `:quiet => false` when you
|
129
|
-
are instantiating the connection or change corresponding attribute:
|
130
|
-
|
131
|
-
c.quiet = false
|
132
|
-
c.get("missing-key") #=> raise Couchbase::Error::NotFound
|
133
|
-
c.get("missing-key", :quiet => true) #=> nil
|
134
|
-
|
135
|
-
The library supports three different formats for representing values:
|
136
|
-
|
137
|
-
* `:document` (default) format supports most of ruby types which could
|
138
|
-
be mapped to JSON data (hashes, arrays, string, numbers). A future
|
139
|
-
version will be able to run map/reduce queries on the values in the
|
140
|
-
document form (hashes)
|
141
|
-
|
142
|
-
* `:plain` This format avoids any conversions to be applied to your
|
143
|
-
data, but your data should be passed as String. This is useful for
|
144
|
-
building custom algorithms or formats. For example to implement a set:
|
145
|
-
http://dustin.github.com/2011/02/17/memcached-set.html
|
146
|
-
|
147
|
-
* `:marshal` Use this format if you'd like to transparently serialize your
|
148
|
-
ruby object with standard `Marshal.dump` and `Marshal.load` methods
|
149
|
-
|
150
|
-
The couchbase API is the superset of [Memcached binary protocol][5], so
|
151
|
-
you can use its operations.
|
152
|
-
|
153
73
|
### Get
|
154
74
|
|
155
75
|
val = c.get("foo")
|
data/lib/couchbase/async.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
require 'couchbase/async/callback'
|
2
19
|
require 'couchbase/async/queue'
|
3
20
|
|
data/lib/couchbase/bucket.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
module Couchbase
|
2
19
|
|
3
20
|
class Bucket
|
@@ -160,6 +177,8 @@ module Couchbase
|
|
160
177
|
url
|
161
178
|
end
|
162
179
|
|
180
|
+
options = Hash[ options.map { |k, v| [k.to_sym, v] } ]
|
181
|
+
|
163
182
|
connection_options = default_options.merge(options).merge(url_options)
|
164
183
|
|
165
184
|
connection_options.each_pair do |key, value|
|
data/lib/couchbase/constants.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
# Author:: Couchbase <info@couchbase.com>
|
2
|
+
# Copyright:: 2011, 2012 Couchbase, Inc.
|
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
|
+
|
1
18
|
module Couchbase
|
2
19
|
module Constants # :nodoc:
|
3
20
|
S_ID = 'id'.freeze
|
data/lib/couchbase/design_doc.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
module Couchbase
|
2
19
|
class DesignDoc
|
3
20
|
|
@@ -58,4 +75,4 @@ module Couchbase
|
|
58
75
|
end
|
59
76
|
|
60
77
|
end
|
61
|
-
end
|
78
|
+
end
|
data/lib/couchbase/error.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
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
|
+
#
|
1
17
|
|
2
18
|
module Couchbase
|
3
19
|
module Error
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
module Couchbase::Operations
|
2
19
|
module Arithmetic
|
3
20
|
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
module Couchbase::Operations
|
2
19
|
module Delete
|
3
20
|
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
module Couchbase::Operations
|
2
19
|
module Get
|
3
20
|
|
@@ -128,25 +145,19 @@ module Couchbase::Operations
|
|
128
145
|
# c.get("foo" => 10, "bar" => 20, :lock => true)
|
129
146
|
# #=> {"foo" => val1, "bar" => val2}
|
130
147
|
#
|
131
|
-
def get(*args)
|
148
|
+
def get(*args, &block)
|
132
149
|
key, options = expand_get_args(args)
|
133
150
|
|
134
151
|
if async?
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
152
|
+
async_get(key, &block)
|
153
|
+
# if block_given?
|
154
|
+
# async_get(key, &Proc.new)
|
155
|
+
# else
|
156
|
+
# async_get(key)
|
157
|
+
# end
|
140
158
|
else
|
141
159
|
sync_block_error if block_given?
|
142
|
-
|
143
|
-
when String, Symbol
|
144
|
-
get_single(key, options)
|
145
|
-
when Array
|
146
|
-
get_bulk(key, options)
|
147
|
-
when Hash
|
148
|
-
get_and_touch(key, options)
|
149
|
-
end
|
160
|
+
get_key(key, options)
|
150
161
|
end
|
151
162
|
end
|
152
163
|
|
@@ -177,7 +188,7 @@ module Couchbase::Operations
|
|
177
188
|
future = client.asyncGet(key)
|
178
189
|
when Array
|
179
190
|
meta = { op: :get }
|
180
|
-
future = client.asyncGetBulk(
|
191
|
+
future = client.asyncGetBulk(key)
|
181
192
|
when Hash
|
182
193
|
# async_get_and_touch(key, options, &block)
|
183
194
|
end
|
@@ -186,6 +197,17 @@ module Couchbase::Operations
|
|
186
197
|
|
187
198
|
private
|
188
199
|
|
200
|
+
def get_key(key, options)
|
201
|
+
case key
|
202
|
+
when String, Symbol
|
203
|
+
get_single(key, options)
|
204
|
+
when Array
|
205
|
+
get_bulk(key, options)
|
206
|
+
when Hash
|
207
|
+
get_and_touch(key, options)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
189
211
|
def expand_get_args(args)
|
190
212
|
options = extract_options_hash(args)
|
191
213
|
key = args.size == 1 ? args.first : args
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
module Couchbase::Operations
|
2
19
|
module Stats
|
3
20
|
|
@@ -1,6 +1,31 @@
|
|
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
|
+
|
1
18
|
module Couchbase::Operations
|
2
19
|
module Store
|
3
20
|
|
21
|
+
STORE_OP_METHODS = {
|
22
|
+
set: -> client, key, value, ttl, transcoder { client.set(key, ttl, value, transcoder) },
|
23
|
+
add: -> client, key, value, ttl, transcoder { client.add(key, ttl, value, transcoder) },
|
24
|
+
replace: -> client, key, value, ttl, transcoder { client.replace(key, ttl, value, transcoder) },
|
25
|
+
append: -> client, key, value, ttl, transcoder { client.append(key, value) },
|
26
|
+
prepend: -> client, key, value, ttl, transcoder { client.prepend(key, value) }
|
27
|
+
}.freeze
|
28
|
+
|
4
29
|
# Unconditionally store the object in the Couchbase
|
5
30
|
#
|
6
31
|
# @since 1.0.0
|
@@ -390,34 +415,33 @@ module Couchbase::Operations
|
|
390
415
|
def store_op(op, key, value, options = {})
|
391
416
|
key, value, ttl, transcoder = store_args_parser(key, value, options)
|
392
417
|
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
client_cas(key, value, ttl, options[:cas], transcoder)
|
398
|
-
else
|
399
|
-
future = client_store_op(op, key, value, ttl, transcoder)
|
400
|
-
if cas = future_cas(future)
|
401
|
-
cas
|
402
|
-
else
|
403
|
-
case op
|
404
|
-
when :replace
|
405
|
-
fail Couchbase::Error::NotFound
|
406
|
-
when :append, :prepend
|
407
|
-
fail Couchbase::Error::NotStored
|
408
|
-
else
|
409
|
-
fail Couchbase::Error::KeyExists
|
410
|
-
end
|
411
|
-
end
|
412
|
-
end
|
413
|
-
when Hash
|
414
|
-
fail TypeError.new if !value.nil?
|
415
|
-
multi_op(op, key)
|
418
|
+
if key.is_a?(String) || key.is_a?(Symbol)
|
419
|
+
store_by_string(op, key.to_s, value, ttl, transcoder, options)
|
420
|
+
elsif key.is_a?(Hash)
|
421
|
+
store_by_hash(op, key, value)
|
416
422
|
else
|
417
423
|
fail TypeError.new
|
418
424
|
end
|
419
425
|
end
|
420
426
|
|
427
|
+
def store_by_string(op, key, value, ttl, transcoder, options)
|
428
|
+
if options[:cas] && op == :set
|
429
|
+
client_cas(key, value, ttl, options[:cas], transcoder)
|
430
|
+
else
|
431
|
+
future = client_store_op(op, key, value, ttl, transcoder)
|
432
|
+
if cas = future_cas(future)
|
433
|
+
cas
|
434
|
+
else
|
435
|
+
fail_store_op(op)
|
436
|
+
end
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
def store_by_hash(op, key, value)
|
441
|
+
fail TypeError.new if !value.nil?
|
442
|
+
multi_op(op, key)
|
443
|
+
end
|
444
|
+
|
421
445
|
def async_store_op(op, key, value, options, &block)
|
422
446
|
key, value, ttl, transcoder = store_args_parser(key, value, options)
|
423
447
|
future = client_store_op(op, key, value, ttl, transcoder)
|
@@ -433,18 +457,7 @@ module Couchbase::Operations
|
|
433
457
|
end
|
434
458
|
|
435
459
|
def client_store_op(op, key, value, ttl, transcoder)
|
436
|
-
|
437
|
-
when :set
|
438
|
-
client.set(key, ttl, value, transcoder)
|
439
|
-
when :add
|
440
|
-
client.add(key, ttl, value, transcoder)
|
441
|
-
when :replace
|
442
|
-
client.replace(key, ttl, value, transcoder)
|
443
|
-
when :append
|
444
|
-
client.append(key, value)
|
445
|
-
when :prepend
|
446
|
-
client.prepend(key, value)
|
447
|
-
end
|
460
|
+
STORE_OP_METHODS[op].call(self.client, key, value, ttl, transcoder)
|
448
461
|
end
|
449
462
|
|
450
463
|
def client_cas(key, value, ttl, cas, transcoder)
|
@@ -456,6 +469,17 @@ module Couchbase::Operations
|
|
456
469
|
end
|
457
470
|
end
|
458
471
|
|
472
|
+
def fail_store_op(op)
|
473
|
+
case op
|
474
|
+
when :replace
|
475
|
+
fail Couchbase::Error::NotFound
|
476
|
+
when :append, :prepend
|
477
|
+
fail Couchbase::Error::NotStored
|
478
|
+
else
|
479
|
+
fail Couchbase::Error::KeyExists
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
459
483
|
end
|
460
484
|
|
461
485
|
end
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
module Couchbase::Operations
|
2
19
|
module Touch
|
3
20
|
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
module Couchbase::Operations
|
2
19
|
module Unlock
|
3
20
|
|
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
module Couchbase::Operations
|
2
19
|
module Utils
|
3
20
|
|
data/lib/couchbase/operations.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
require 'couchbase/operations/touch'
|
2
19
|
require 'couchbase/operations/store'
|
3
20
|
require 'couchbase/operations/get'
|
data/lib/couchbase/query.rb
CHANGED
@@ -1,3 +1,21 @@
|
|
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
|
+
|
1
19
|
module Couchbase
|
2
20
|
class Query
|
3
21
|
|
@@ -50,7 +68,7 @@ module Couchbase
|
|
50
68
|
end
|
51
69
|
end
|
52
70
|
|
53
|
-
|
71
|
+
|
54
72
|
# @option params [true, false] :quiet (true) Do not raise error if
|
55
73
|
# associated document not found in the memory. If the parameter +true+
|
56
74
|
# will use +nil+ value instead.
|
@@ -65,7 +83,7 @@ module Couchbase
|
|
65
83
|
# view request is dropped (milliseconds)
|
66
84
|
|
67
85
|
|
68
|
-
# @option params [Hash] :body
|
86
|
+
# @option params [Hash] :body
|
69
87
|
query
|
70
88
|
end
|
71
89
|
|
data/lib/couchbase/result.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
module Couchbase
|
2
19
|
class Result
|
3
20
|
|
data/lib/couchbase/transcoder.rb
CHANGED
data/lib/couchbase/version.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
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
|
+
|
1
18
|
module Couchbase
|
2
|
-
VERSION = '0.1.
|
19
|
+
VERSION = '0.1.2'
|
3
20
|
end
|
data/lib/couchbase.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
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
|
+
#
|
1
17
|
|
2
18
|
unless RUBY_PLATFORM =~ /java/
|
3
19
|
error "This gem is only compatible with a java-based ruby environment like JRuby."
|
@@ -129,7 +145,7 @@ module Couchbase
|
|
129
145
|
else
|
130
146
|
"default"
|
131
147
|
end
|
132
|
-
@@buckets.update { |buckets| buckets[name] ||= connect(connection_options) }
|
148
|
+
@@buckets.update { |buckets| buckets[name] ||= connect(connection_options.merge(bucket: name)) }
|
133
149
|
@@buckets.value[name]
|
134
150
|
end
|
135
151
|
|
data/test/profile/benchmark.rb
CHANGED
@@ -54,6 +54,7 @@ class Bench
|
|
54
54
|
@k6 = "Long3" * 40]
|
55
55
|
|
56
56
|
@cb = Couchbase.new
|
57
|
+
@cl = @cb.client
|
57
58
|
|
58
59
|
# Ensure it is JITed
|
59
60
|
2_000.times do
|
@@ -71,9 +72,9 @@ class Bench
|
|
71
72
|
end
|
72
73
|
|
73
74
|
x.report('java set') do
|
74
|
-
@
|
75
|
-
@
|
76
|
-
@
|
75
|
+
@cl.set(@k1, MultiJson.dump(@value)).get
|
76
|
+
@cl.set(@k2, MultiJson.dump(@value)).get
|
77
|
+
@cl.set(@k3, MultiJson.dump(@value)).get
|
77
78
|
end
|
78
79
|
|
79
80
|
x.report('jruby get') do
|
@@ -83,9 +84,17 @@ class Bench
|
|
83
84
|
end
|
84
85
|
|
85
86
|
x.report('java get') do
|
86
|
-
MultiJson.load @
|
87
|
-
MultiJson.load @
|
88
|
-
MultiJson.load @
|
87
|
+
MultiJson.load @cl.get(@k1)
|
88
|
+
MultiJson.load @cl.get(@k2)
|
89
|
+
MultiJson.load @cl.get(@k3)
|
90
|
+
end
|
91
|
+
|
92
|
+
x.report('jruby get multi') do
|
93
|
+
@cb.get([@k1, @k2, @k3])
|
94
|
+
end
|
95
|
+
|
96
|
+
x.report('java get multi') do
|
97
|
+
@cl.getBulk([@k1, @k2, @k3])
|
89
98
|
end
|
90
99
|
|
91
100
|
x.report('jruby delete') do
|
@@ -98,12 +107,12 @@ class Bench
|
|
98
107
|
end
|
99
108
|
|
100
109
|
x.report('java delete') do
|
101
|
-
@
|
102
|
-
@
|
103
|
-
@
|
104
|
-
@
|
105
|
-
@
|
106
|
-
@
|
110
|
+
@cl.set @k1, ''
|
111
|
+
@cl.set @k2, ''
|
112
|
+
@cl.set @k3, ''
|
113
|
+
@cl.delete @k1
|
114
|
+
@cl.delete @k2
|
115
|
+
@cl.delete @k3
|
107
116
|
end
|
108
117
|
|
109
118
|
x.report('jruby get missing') do
|
@@ -113,50 +122,50 @@ class Bench
|
|
113
122
|
end
|
114
123
|
|
115
124
|
x.report('java get missing') do
|
116
|
-
@
|
117
|
-
@
|
118
|
-
@
|
125
|
+
@cl.get @k1
|
126
|
+
@cl.get @k2
|
127
|
+
@cl.get @k3
|
119
128
|
end
|
120
129
|
|
121
|
-
x.report('jruby async set') do
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
x.report('java async set') do
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
x.report('jruby async get') do
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
end
|
150
|
-
|
151
|
-
x.report('java async get') do
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
end
|
130
|
+
# x.report('jruby async set') do
|
131
|
+
# @cb.run do
|
132
|
+
# 100.times do
|
133
|
+
# @cb.set @k1, @value
|
134
|
+
# @cb.set @k2, @value
|
135
|
+
# @cb.set @k3, @value
|
136
|
+
# end
|
137
|
+
# end
|
138
|
+
# end
|
139
|
+
|
140
|
+
# x.report('java async set') do
|
141
|
+
# futures = []
|
142
|
+
# 100.times do
|
143
|
+
# futures << @cb.client.set(@k1, MultiJson.dump(@value))
|
144
|
+
# futures << @cb.client.set(@k2, MultiJson.dump(@value))
|
145
|
+
# futures << @cb.client.set(@k3, MultiJson.dump(@value))
|
146
|
+
# end
|
147
|
+
# futures.each(&:get)
|
148
|
+
# end
|
149
|
+
|
150
|
+
# x.report('jruby async get') do
|
151
|
+
# @cb.run do
|
152
|
+
# 100.times do
|
153
|
+
# @cb.get @k1
|
154
|
+
# @cb.get @k2
|
155
|
+
# @cb.get @k3
|
156
|
+
# end
|
157
|
+
# end
|
158
|
+
# end
|
159
|
+
|
160
|
+
# x.report('java async get') do
|
161
|
+
# futures = []
|
162
|
+
# 100.times do
|
163
|
+
# futures << @cb.client.asyncGet(@k1)
|
164
|
+
# futures << @cb.client.asyncGet(@k2)
|
165
|
+
# futures << @cb.client.asyncGet(@k3)
|
166
|
+
# end
|
167
|
+
# futures.each(&:get)
|
168
|
+
# end
|
160
169
|
|
161
170
|
end
|
162
171
|
|
data/test/test_bucket.rb
CHANGED
@@ -210,4 +210,10 @@ class TestBucket < MiniTest::Test
|
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
213
|
+
def test_it_converts_options_keys_to_symbols
|
214
|
+
bucket = Couchbase::Bucket.new('bucket' => 'notdefault', 'hostname' => 'example.com', 'async' => true)
|
215
|
+
assert_equal 'notdefault', bucket.bucket
|
216
|
+
assert_equal 'example.com', bucket.hostname
|
217
|
+
end
|
218
|
+
|
213
219
|
end
|
data/test/test_couchbase.rb
CHANGED
data/test/test_get.rb
CHANGED
@@ -114,7 +114,6 @@ class TestGet < MiniTest::Test
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def test_missing_in_quiet_mode
|
117
|
-
skip
|
118
117
|
connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port, :quiet => true)
|
119
118
|
cas1 = connection.set(uniq_id(1), "foo1")
|
120
119
|
cas2 = connection.set(uniq_id(2), "foo2")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couchbase-jruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|