couchbase 1.1.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -0
- data/.travis.yml +11 -0
- data/.yardopts +5 -0
- data/Gemfile +4 -0
- data/HISTORY.markdown +75 -0
- data/LICENSE +201 -0
- data/README.markdown +370 -0
- data/Rakefile +22 -0
- data/couchbase.gemspec +47 -0
- data/ext/couchbase_ext/couchbase_ext.c +3464 -0
- data/ext/couchbase_ext/extconf.rb +113 -0
- data/lib/couchbase.rb +81 -0
- data/lib/couchbase/bucket.rb +72 -0
- data/lib/couchbase/version.rb +21 -0
- data/tasks/benchmark.rake +6 -0
- data/tasks/compile.rake +124 -0
- data/tasks/doc.rake +27 -0
- data/tasks/test.rake +94 -0
- data/tasks/util.rake +21 -0
- data/test/profile/.gitignore +1 -0
- data/test/profile/Gemfile +6 -0
- data/test/profile/benchmark.rb +195 -0
- data/test/setup.rb +167 -0
- data/test/test_arithmetic.rb +109 -0
- data/test/test_async.rb +235 -0
- data/test/test_bucket.rb +227 -0
- data/test/test_cas.rb +59 -0
- data/test/test_couchbase.rb +28 -0
- data/test/test_delete.rb +63 -0
- data/test/test_errors.rb +82 -0
- data/test/test_flush.rb +49 -0
- data/test/test_format.rb +98 -0
- data/test/test_get.rb +311 -0
- data/test/test_stats.rb +57 -0
- data/test/test_store.rb +186 -0
- data/test/test_touch.rb +69 -0
- data/test/test_version.rb +52 -0
- metadata +197 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
before_install:
|
2
|
+
- wget -O- http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add -
|
3
|
+
- echo deb http://packages.couchbase.com/ubuntu lucid lucid/main | sudo tee /etc/apt/sources.list.d/couchbase.list
|
4
|
+
- sudo apt-get update
|
5
|
+
- sudo apt-get -y install libevent-dev libvbucket-dev libcouchbase-dev
|
6
|
+
|
7
|
+
rvm:
|
8
|
+
- 1.8.7
|
9
|
+
- 1.9.2
|
10
|
+
- 1.9.3
|
11
|
+
- ree
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/HISTORY.markdown
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
## 1.1.0 / 2012-03-07
|
2
|
+
|
3
|
+
* Timeout support (CCBC-20)
|
4
|
+
* Implement disconnect/reconnect interface
|
5
|
+
* Improve error handling code
|
6
|
+
* Use URI parser from stdlib
|
7
|
+
* Improve the documentation and the tests
|
8
|
+
* Remove direct dependency on libevent
|
9
|
+
* Remove sasl dependency
|
10
|
+
* Fix storing empty line and nil
|
11
|
+
* Allow running tests on real cluster
|
12
|
+
* Cross-build for windows
|
13
|
+
* Keep connections in thread local storage
|
14
|
+
* Add block execution time to timeout
|
15
|
+
* Implement VERSION command
|
16
|
+
* Configure Travis-CI
|
17
|
+
|
18
|
+
## 1.0.0 / 2011-12-23
|
19
|
+
|
20
|
+
* Implement all operations using libcouchbase as backend
|
21
|
+
* Remove views code. It will be re-added in 1.1 version
|
22
|
+
|
23
|
+
## 0.9.8 / 2011-12-16
|
24
|
+
|
25
|
+
* Fix RCBC-10: It was impossible to store data in non-default buckets
|
26
|
+
|
27
|
+
## 0.9.7 / 2011-10-04
|
28
|
+
|
29
|
+
* Fix design doc removing
|
30
|
+
* Fix 'set' method signature: add missing options argument
|
31
|
+
* Rename gem to 'couchbase' for easy of use. The github project still
|
32
|
+
is 'couchbase-ruby-client'
|
33
|
+
|
34
|
+
## 0.9.6 / 2011-10-04
|
35
|
+
|
36
|
+
* Fix bug with decoding multiget result
|
37
|
+
* Allow create design documents from IO and String
|
38
|
+
* Rename json format to document, and describe possible formats
|
39
|
+
* Allow to handle errors in view result stream
|
40
|
+
* Remove dependency on libyajl library: it bundled with yaji now
|
41
|
+
* Update rake tasks: create zip- and tar-balls
|
42
|
+
|
43
|
+
## 0.9.5 / 2011-08-24
|
44
|
+
|
45
|
+
* Update installation notes in README
|
46
|
+
|
47
|
+
## 0.9.4 / 2011-08-24
|
48
|
+
|
49
|
+
* Use streaming json parser to iterate over view results
|
50
|
+
* Update memcached gem dependency to v1.3
|
51
|
+
* Proxy TOUCH command to memcached client
|
52
|
+
* Fix minor bugs in RestClient and Document classes
|
53
|
+
* Disable CouchDB API for nodes without 'couchApiBase' key provided.
|
54
|
+
* Fix bug with unicode parsing in config listener
|
55
|
+
* Add more unit tests
|
56
|
+
|
57
|
+
## 0.9.3 / 2011-07-29
|
58
|
+
|
59
|
+
* Use Latch (via Mutex and ConditionVariable) to wait until initial
|
60
|
+
setup will be finished.
|
61
|
+
* Update prefix for development views (from '$dev_' to 'dev_')
|
62
|
+
|
63
|
+
## 0.9.2 / 2011-07-29
|
64
|
+
|
65
|
+
* Use zero TTL by default to store records forever
|
66
|
+
* Update documentation
|
67
|
+
* Sleep if setup isn't done
|
68
|
+
|
69
|
+
## 0.9.1 / 2011-07-25
|
70
|
+
|
71
|
+
* Minor bugfix for RestClient initialization
|
72
|
+
|
73
|
+
## 0.9.0 / 2011-07-25
|
74
|
+
|
75
|
+
* Initial public release
|
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.markdown
ADDED
@@ -0,0 +1,370 @@
|
|
1
|
+
# Couchbase Ruby Client [![Build Status](https://secure.travis-ci.org/avsej/couchbase-ruby-client.png?branch=master)](http://travis-ci.org/avsej/couchbase-ruby-client)
|
2
|
+
|
3
|
+
This is the official client library for use with Couchbase Server.
|
4
|
+
|
5
|
+
## SUPPORT
|
6
|
+
|
7
|
+
If you found an issue, please file it in our [JIRA][1]. Also you are
|
8
|
+
always welcome on `#libcouchbase` channel at [freenode.net IRC servers][2].
|
9
|
+
|
10
|
+
Documentation: [http://rdoc.info/gems/couchbase](http://rdoc.info/gems/couchbase)
|
11
|
+
|
12
|
+
## INSTALL
|
13
|
+
|
14
|
+
This gem depends [libcouchbase][3]. In most cases installing
|
15
|
+
libcouchbase doesn't take much effort.
|
16
|
+
|
17
|
+
### MacOS (Homebrew)
|
18
|
+
|
19
|
+
$ brew install libcouchbase
|
20
|
+
|
21
|
+
Or if [our pull requests][4] for isn't yet merged:
|
22
|
+
|
23
|
+
$ brew install https://github.com/avsej/homebrew/raw/libvbucket/Library/Formula/libvbucket.rb
|
24
|
+
$ brew install https://github.com/avsej/homebrew/raw/libcouchbase/Library/Formula/libcouchbase.rb
|
25
|
+
|
26
|
+
### Debian (Ubuntu)
|
27
|
+
|
28
|
+
Add the appropriate line to /etc/apt/sources.list.d/couchbase.list for
|
29
|
+
your OS release:
|
30
|
+
|
31
|
+
# Ubuntu 11.10 Oneiric Ocelot (Debian unstable)
|
32
|
+
deb http://packages.couchbase.com/ubuntu oneiric oneiric/main
|
33
|
+
|
34
|
+
# Ubuntu 10.04 Lucid Lynx (Debian stable or testing)
|
35
|
+
deb http://packages.couchbase.com/ubuntu lucid lucid/main
|
36
|
+
|
37
|
+
Import Couchbase PGP key:
|
38
|
+
|
39
|
+
wget -O- http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add -
|
40
|
+
|
41
|
+
Then install them
|
42
|
+
|
43
|
+
$ sudo apt-get update && sudo apt-get install libcouchbase-dev
|
44
|
+
|
45
|
+
### Centos (Redhat and rpm-based systems)
|
46
|
+
|
47
|
+
Add these lines to /etc/yum.repos.d/couchbase.repo using the correct architecture
|
48
|
+
|
49
|
+
[couchbase]
|
50
|
+
name = Couchbase package repository
|
51
|
+
baseurl = http://packages.couchbase.com/rpm/5.5/i386
|
52
|
+
|
53
|
+
[couchbase]
|
54
|
+
name = Couchbase package repository
|
55
|
+
baseurl = http:///packages.couchbase.com/rpm/5.5/x86_64
|
56
|
+
|
57
|
+
Then to install libcouchbase itself, run:
|
58
|
+
|
59
|
+
$ sudo yum update && sudo yum install libcouchbase-devel
|
60
|
+
|
61
|
+
### Windows
|
62
|
+
|
63
|
+
There no additional dependencies for Windows systems. The gem carry
|
64
|
+
prebuilt binary for it.
|
65
|
+
|
66
|
+
### Couchbase gem
|
67
|
+
|
68
|
+
Now install the couchbase gem itself
|
69
|
+
|
70
|
+
$ gem install couchbase
|
71
|
+
|
72
|
+
## USAGE
|
73
|
+
|
74
|
+
First of all you need to load library:
|
75
|
+
|
76
|
+
require 'couchbase'
|
77
|
+
|
78
|
+
There are several ways to establish new connection to Couchbase Server.
|
79
|
+
By default it uses the `http://localhost:8091/pools/default/buckets/default`
|
80
|
+
as the endpoint. The client will automatically adjust configuration when
|
81
|
+
the cluster will rebalance its nodes when nodes are added or deleted
|
82
|
+
therefore this client is "smart".
|
83
|
+
|
84
|
+
c = Couchbase.new
|
85
|
+
|
86
|
+
This is equivalent to following forms:
|
87
|
+
|
88
|
+
c = Couchbase.new("http://localhost:8091/pools/default/buckets/default")
|
89
|
+
c = Couchbase.new("http://localhost:8091/pools/default")
|
90
|
+
c = Couchbase.new("http://localhost:8091")
|
91
|
+
c = Couchbase.new(:host => "localhost")
|
92
|
+
c = Couchbase.new(:host => "localhost", :port => 8091)
|
93
|
+
c = Couchbase.new(:pool => "default", :bucket => "default")
|
94
|
+
|
95
|
+
The hash parameters take precedence on string URL.
|
96
|
+
|
97
|
+
The library supports both synchronous and asynchronous mode. In
|
98
|
+
asynchronous mode all operations will return control to caller
|
99
|
+
without blocking current thread. You can pass the block to method and it
|
100
|
+
will be called with result when the operation will be completed. You
|
101
|
+
need to run event loop when you scheduled your operations:
|
102
|
+
|
103
|
+
c = Couchbase.new
|
104
|
+
c.run do |conn|
|
105
|
+
conn.get("foo") {|ret| puts ret.value}
|
106
|
+
conn.set("bar", "baz")
|
107
|
+
end
|
108
|
+
|
109
|
+
The handlers could be nested
|
110
|
+
|
111
|
+
c.run do |conn|
|
112
|
+
conn.get("foo") do |ret|
|
113
|
+
conn.incr(ret.value, :initial => 0)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
The asynchronous callback receives instance of `Couchbase::Result` which
|
118
|
+
responds to several methods to figure out what was happened:
|
119
|
+
|
120
|
+
* `success?`. Returns `true` if operation succed.
|
121
|
+
|
122
|
+
* `error`. Returns `nil` or exception object (subclass of
|
123
|
+
`Couchbase::Error::Base`) if something went wrong.
|
124
|
+
|
125
|
+
* `key`
|
126
|
+
|
127
|
+
* `value`
|
128
|
+
|
129
|
+
* `flags`
|
130
|
+
|
131
|
+
* `cas`. The CAS version tag.
|
132
|
+
|
133
|
+
* `node`. Node address. It is used in flush and stats commands.
|
134
|
+
|
135
|
+
* `operation`. The symbol, representing an operation.
|
136
|
+
|
137
|
+
|
138
|
+
To handle global errors in async mode `#on_error` callback should be
|
139
|
+
used. It can be set in following fashions:
|
140
|
+
|
141
|
+
c.on_error do |opcode, key, exc|
|
142
|
+
# ...
|
143
|
+
end
|
144
|
+
|
145
|
+
handler = lambda {|opcode, key, exc| }
|
146
|
+
c.on_error = handler
|
147
|
+
|
148
|
+
By default connection uses `:quiet` mode. This mean it won't raise
|
149
|
+
exceptions when the given key is not exists:
|
150
|
+
|
151
|
+
c.get("missing-key") #=> nil
|
152
|
+
|
153
|
+
It could be useful when you are trying to make you code a bit efficient
|
154
|
+
by avoiding exception handling. (See `#add` and `#replace` operations).
|
155
|
+
You can turn on these exception by passing `:quiet => false` when you
|
156
|
+
are instantiating the connection or change corresponding attribute:
|
157
|
+
|
158
|
+
c.quiet = false
|
159
|
+
c.get("missing-key") #=> raise Couchbase::Error::NotFound
|
160
|
+
c.get("missing-key", :quiet => true) #=> nil
|
161
|
+
|
162
|
+
The library supports three different formats for representing values:
|
163
|
+
|
164
|
+
* `:document` (default) format supports most of ruby types which could
|
165
|
+
be mapped to JSON data (hashes, arrays, string, numbers). A future
|
166
|
+
version will be able to run map/reduce queries on the values in the
|
167
|
+
document form (hashes)
|
168
|
+
|
169
|
+
* `:marshal` This format avoids any conversions to be applied to your
|
170
|
+
data, but your data should be passed as String. This is useful for
|
171
|
+
building custom algorithms or formats. For example to implement a set:
|
172
|
+
http://dustin.github.com/2011/02/17/memcached-set.html
|
173
|
+
|
174
|
+
* `:plain` Use this format if you'd like to transparently serialize your
|
175
|
+
ruby object with standard `Marshal.dump` and `Marshal.load` methods
|
176
|
+
|
177
|
+
The couchbase API is the superset of [Memcached binary protocol][5], so
|
178
|
+
you can use its operations.
|
179
|
+
|
180
|
+
### Get
|
181
|
+
|
182
|
+
val = c.get("foo")
|
183
|
+
val, flags, cas = c.get("foo", :extended => true)
|
184
|
+
|
185
|
+
Get and touch
|
186
|
+
|
187
|
+
val = c.get("foo", :ttl => 10)
|
188
|
+
|
189
|
+
Get multiple values. In quiet mode will put `nil` values on missing
|
190
|
+
positions:
|
191
|
+
|
192
|
+
vals = c.get("foo", "bar", "baz")
|
193
|
+
val_foo, val_bar, val_baz = c.get("foo", "bar", "baz")
|
194
|
+
c.run do
|
195
|
+
c.get("foo") do |ret|
|
196
|
+
ret.success?
|
197
|
+
ret.error
|
198
|
+
ret.key
|
199
|
+
ret.value
|
200
|
+
ret.flags
|
201
|
+
ret.cas
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
Get multiple values with extended information. The result will
|
206
|
+
represented by hash with tuples `[value, flags, cas]` as a value.
|
207
|
+
|
208
|
+
vals = c.get("foo", "bar", "baz", :extended => true)
|
209
|
+
vals.inspect #=> {"baz"=>["3", 0, 4784582192793125888],
|
210
|
+
"foo"=>["1", 0, 8835713818674332672],
|
211
|
+
"bar"=>["2", 0, 10805929834096100352]}
|
212
|
+
|
213
|
+
Hash-like syntax
|
214
|
+
|
215
|
+
c["foo"]
|
216
|
+
c["foo", "bar", "baz"]
|
217
|
+
c["foo", {:extended => true}]
|
218
|
+
c["foo", :extended => true] # for ruby 1.9.x only
|
219
|
+
|
220
|
+
### Touch
|
221
|
+
|
222
|
+
c.touch("foo") # use :default_ttl
|
223
|
+
c.touch("foo", 10)
|
224
|
+
c.touch("foo", :ttl => 10)
|
225
|
+
c.touch("foo" => 10, "bar" => 20)
|
226
|
+
c.touch("foo" => 10, "bar" => 20){|key, success| }
|
227
|
+
|
228
|
+
### Set
|
229
|
+
|
230
|
+
c.set("foo", "bar")
|
231
|
+
c.set("foo", "bar", :flags => 0x1000, :ttl => 30, :format => :plain)
|
232
|
+
c["foo"] = "bar"
|
233
|
+
c["foo", {:flags => 0x1000, :format => :plain}] = "bar"
|
234
|
+
c["foo", :flags => 0x1000] = "bar" # for ruby 1.9.x only
|
235
|
+
c.set("foo", "bar", :cas => 8835713818674332672)
|
236
|
+
c.set("foo", "bar"){|cas, key, operation| }
|
237
|
+
|
238
|
+
### Add
|
239
|
+
|
240
|
+
Add command will fail if the key already exists. It accepts the same
|
241
|
+
options as set command above.
|
242
|
+
|
243
|
+
c.add("foo", "bar")
|
244
|
+
c.add("foo", "bar", :flags => 0x1000, :ttl => 30, :format => :plain)
|
245
|
+
|
246
|
+
### Replace
|
247
|
+
|
248
|
+
The replace command will fail if the key already exists. It accepts the same
|
249
|
+
options as set command above.
|
250
|
+
|
251
|
+
c.replace("foo", "bar")
|
252
|
+
|
253
|
+
### Prepend/Append
|
254
|
+
|
255
|
+
These commands are meaningful when you are using the `:plain` value format,
|
256
|
+
because the concatenation is performed by server which has no idea how
|
257
|
+
to merge to JSON values or values in ruby Marshal format. You may receive
|
258
|
+
an `Couchbase::Error::ValueFormat` error.
|
259
|
+
|
260
|
+
c.set("foo", "world")
|
261
|
+
c.append("foo", "!")
|
262
|
+
c.prepend("foo", "Hello, ")
|
263
|
+
c.get("foo") #=> "Hello, world!"
|
264
|
+
|
265
|
+
### Increment/Decrement
|
266
|
+
|
267
|
+
These commands increment the value assigned to the key. It will raise
|
268
|
+
Couchbase::Error::DeltaBadval if the delta or value is not a number.
|
269
|
+
|
270
|
+
c.set("foo", 1)
|
271
|
+
c.incr("foo") #=> 2
|
272
|
+
c.incr("foo", :delta => 2) #=> 4
|
273
|
+
c.incr("foo", 4) #=> 8
|
274
|
+
c.incr("foo", -1) #=> 7
|
275
|
+
c.incr("foo", -100) #=> 0
|
276
|
+
c.run do
|
277
|
+
c.incr("foo") do |ret|
|
278
|
+
ret.success?
|
279
|
+
ret.value
|
280
|
+
ret.cas
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
c.set("foo", 10)
|
285
|
+
c.decr("foo", 1) #=> 9
|
286
|
+
c.decr("foo", 100) #=> 0
|
287
|
+
c.run do
|
288
|
+
c.decr("foo") do |ret|
|
289
|
+
ret.success?
|
290
|
+
ret.value
|
291
|
+
ret.cas
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
c.incr("missing1", :initial => 10) #=> 10
|
296
|
+
c.incr("missing1", :initial => 10) #=> 11
|
297
|
+
c.incr("missing2", :create => true) #=> 0
|
298
|
+
c.incr("missing2", :create => true) #=> 1
|
299
|
+
|
300
|
+
Note that it isn't the same as increment/decrement in ruby, which is
|
301
|
+
performed on client side with following `set` operation:
|
302
|
+
|
303
|
+
c["foo"] = 10
|
304
|
+
c["foo"] -= 20 #=> -10
|
305
|
+
|
306
|
+
### Delete
|
307
|
+
|
308
|
+
c.delete("foo")
|
309
|
+
c.delete("foo", :cas => 8835713818674332672)
|
310
|
+
c.delete("foo", 8835713818674332672)
|
311
|
+
c.run do
|
312
|
+
c.delete do |ret|
|
313
|
+
ret.success?
|
314
|
+
ret.key
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
### Flush
|
319
|
+
|
320
|
+
Flush the items in the cluster.
|
321
|
+
|
322
|
+
c.flush
|
323
|
+
c.run do
|
324
|
+
c.flush do |ret|
|
325
|
+
ret.success?
|
326
|
+
ret.node
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
### Stats
|
331
|
+
|
332
|
+
Return statistics from each node in the cluster
|
333
|
+
|
334
|
+
c.stats
|
335
|
+
c.stats(:memory)
|
336
|
+
c.run do
|
337
|
+
c.stats do |ret|
|
338
|
+
ret.success?
|
339
|
+
ret.node
|
340
|
+
ret.key
|
341
|
+
ret.value
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
The result is represented as a hash with the server node address as
|
346
|
+
the key and stats as key-value pairs.
|
347
|
+
|
348
|
+
{
|
349
|
+
"172.16.16.76:12008"=>
|
350
|
+
{
|
351
|
+
"threads"=>"4",
|
352
|
+
"connection_structures"=>"22",
|
353
|
+
"ep_max_txn_size"=>"10000",
|
354
|
+
# ...
|
355
|
+
},
|
356
|
+
"172.16.16.76:12000"=>
|
357
|
+
{
|
358
|
+
"threads"=>"4",
|
359
|
+
"connection_structures"=>"447",
|
360
|
+
"ep_max_txn_size"=>"10000",
|
361
|
+
# ...
|
362
|
+
},
|
363
|
+
# ...
|
364
|
+
}
|
365
|
+
|
366
|
+
[1]: http://couchbase.com/issues/browse/RCBC
|
367
|
+
[2]: http://freenode.net/irc_servers.shtml
|
368
|
+
[3]: http://www.couchbase.com/develop/c/current
|
369
|
+
[4]: https://github.com/mxcl/homebrew/pulls/avsej
|
370
|
+
[5]: http://code.google.com/p/memcached/wiki/BinaryProtocolRevamped
|