jmoses-couchbase 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/.gitignore +15 -0
  2. data/.travis.yml +22 -0
  3. data/.yardopts +5 -0
  4. data/CONTRIBUTING.markdown +75 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +201 -0
  7. data/Makefile +3 -0
  8. data/README.markdown +665 -0
  9. data/RELEASE_NOTES.markdown +819 -0
  10. data/Rakefile +20 -0
  11. data/couchbase.gemspec +49 -0
  12. data/examples/chat-em/Gemfile +7 -0
  13. data/examples/chat-em/README.markdown +45 -0
  14. data/examples/chat-em/server.rb +82 -0
  15. data/examples/chat-goliath-grape/Gemfile +5 -0
  16. data/examples/chat-goliath-grape/README.markdown +50 -0
  17. data/examples/chat-goliath-grape/app.rb +67 -0
  18. data/examples/chat-goliath-grape/config/app.rb +20 -0
  19. data/examples/transcoders/Gemfile +3 -0
  20. data/examples/transcoders/README.markdown +59 -0
  21. data/examples/transcoders/cb-zcat +40 -0
  22. data/examples/transcoders/cb-zcp +45 -0
  23. data/examples/transcoders/gzip_transcoder.rb +49 -0
  24. data/examples/transcoders/options.rb +54 -0
  25. data/ext/couchbase_ext/.gitignore +4 -0
  26. data/ext/couchbase_ext/arguments.c +956 -0
  27. data/ext/couchbase_ext/arithmetic.c +316 -0
  28. data/ext/couchbase_ext/bucket.c +1373 -0
  29. data/ext/couchbase_ext/context.c +65 -0
  30. data/ext/couchbase_ext/couchbase_ext.c +1364 -0
  31. data/ext/couchbase_ext/couchbase_ext.h +644 -0
  32. data/ext/couchbase_ext/delete.c +163 -0
  33. data/ext/couchbase_ext/eventmachine_plugin.c +452 -0
  34. data/ext/couchbase_ext/extconf.rb +169 -0
  35. data/ext/couchbase_ext/get.c +316 -0
  36. data/ext/couchbase_ext/gethrtime.c +129 -0
  37. data/ext/couchbase_ext/http.c +432 -0
  38. data/ext/couchbase_ext/multithread_plugin.c +1090 -0
  39. data/ext/couchbase_ext/observe.c +171 -0
  40. data/ext/couchbase_ext/plugin_common.c +171 -0
  41. data/ext/couchbase_ext/result.c +129 -0
  42. data/ext/couchbase_ext/stats.c +163 -0
  43. data/ext/couchbase_ext/store.c +542 -0
  44. data/ext/couchbase_ext/timer.c +192 -0
  45. data/ext/couchbase_ext/touch.c +186 -0
  46. data/ext/couchbase_ext/unlock.c +176 -0
  47. data/ext/couchbase_ext/utils.c +551 -0
  48. data/ext/couchbase_ext/version.c +142 -0
  49. data/lib/action_dispatch/middleware/session/couchbase_store.rb +38 -0
  50. data/lib/active_support/cache/couchbase_store.rb +430 -0
  51. data/lib/couchbase.rb +155 -0
  52. data/lib/couchbase/bucket.rb +457 -0
  53. data/lib/couchbase/cluster.rb +119 -0
  54. data/lib/couchbase/connection_pool.rb +58 -0
  55. data/lib/couchbase/constants.rb +12 -0
  56. data/lib/couchbase/result.rb +26 -0
  57. data/lib/couchbase/transcoder.rb +120 -0
  58. data/lib/couchbase/utils.rb +62 -0
  59. data/lib/couchbase/version.rb +21 -0
  60. data/lib/couchbase/view.rb +506 -0
  61. data/lib/couchbase/view_row.rb +272 -0
  62. data/lib/ext/multi_json_fix.rb +56 -0
  63. data/lib/rack/session/couchbase.rb +108 -0
  64. data/tasks/benchmark.rake +6 -0
  65. data/tasks/compile.rake +160 -0
  66. data/tasks/test.rake +100 -0
  67. data/tasks/util.rake +21 -0
  68. data/test/profile/.gitignore +1 -0
  69. data/test/profile/Gemfile +6 -0
  70. data/test/profile/benchmark.rb +195 -0
  71. data/test/setup.rb +178 -0
  72. data/test/test_arithmetic.rb +185 -0
  73. data/test/test_async.rb +316 -0
  74. data/test/test_bucket.rb +276 -0
  75. data/test/test_cas.rb +235 -0
  76. data/test/test_couchbase.rb +77 -0
  77. data/test/test_couchbase_connection_pool.rb +77 -0
  78. data/test/test_couchbase_rails_cache_store.rb +361 -0
  79. data/test/test_delete.rb +120 -0
  80. data/test/test_errors.rb +82 -0
  81. data/test/test_eventmachine.rb +70 -0
  82. data/test/test_format.rb +164 -0
  83. data/test/test_get.rb +407 -0
  84. data/test/test_stats.rb +57 -0
  85. data/test/test_store.rb +216 -0
  86. data/test/test_timer.rb +42 -0
  87. data/test/test_touch.rb +97 -0
  88. data/test/test_unlock.rb +119 -0
  89. data/test/test_utils.rb +58 -0
  90. data/test/test_version.rb +52 -0
  91. metadata +353 -0
@@ -0,0 +1,15 @@
1
+ *.bundle
2
+ *.gem
3
+ *.so
4
+ .timestamp
5
+ .yardoc
6
+ Gemfile.lock
7
+ core*
8
+ doc/
9
+ ext/couchbase/Makefile
10
+ ext/couchbase/mkmf.log
11
+ lib/couchbase_ext.rb
12
+ pkg/*
13
+ ports
14
+ test/CouchbaseMock.jar
15
+ tmp
@@ -0,0 +1,22 @@
1
+ before_install:
2
+ - sudo rm -rf /etc/apt/sources.list.d/couchdb-ppa-source.list
3
+ - sudo rm -rf /etc/apt/sources.list.d/mongodb.list
4
+ - sudo rm -rf /etc/apt/sources.list.d/datastax-source.list
5
+ - sudo rm -rf /etc/apt/sources.list.d/rabbitmq-source.list
6
+ - sudo rm -rf /etc/apt/sources.list.d/mapopa-source.list
7
+ - sudo rm -rf /etc/apt/sources.list.d/webupd8team-java-ppa-source.list
8
+ - sudo rm -rf /etc/apt/sources.list.d/maven3-ppa-source.list
9
+ - wget -O- http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add -
10
+ - echo deb http://packages.couchbase.com/snapshot/ubuntu oneiric oneiric/main | sudo tee /etc/apt/sources.list.d/couchbase.list
11
+ - sudo apt-get update
12
+ - sudo apt-get -y install libcouchbase2-dev
13
+
14
+ rvm:
15
+ - 1.8.7
16
+ - 1.9.2
17
+ - 1.9.3
18
+ - ree
19
+
20
+ notifications:
21
+ email:
22
+ - sergey@couchbase.com
@@ -0,0 +1,5 @@
1
+ --protected
2
+ --no-private
3
+ -
4
+ README.markdown
5
+ RELEASE_NOTES.markdown
@@ -0,0 +1,75 @@
1
+ We've decided to use "gerrit" for our code review system, making it
2
+ easier for all of us to contribute with code and comments.
3
+
4
+ 1. Visit http://review.couchbase.org and "Register" for an account
5
+ 2. Review http://review.couchbase.org/static/individual_agreement.html
6
+ 3. Agree to agreement by visiting http://review.couchbase.org/#/settings/agreements
7
+ 4. If you do not receive an email, please contact us
8
+ 5. Check out the `couchbase-ruby-client` area http://review.couchbase.org/#/q/status:open+project:couchbase-ruby-client,n,z
9
+ 6. Join us on IRC at #libcouchbase on Freenode :-)
10
+
11
+ We normally don't go looking for stuff in gerrit, so you should add at
12
+ least me `"Sergey Avseyev" <sergey.avseyev@gmail.com>` as a reviewer
13
+ for your patch (and I'll know who else to add and add them for you).
14
+
15
+ ## Contributing Using Repo Tool
16
+
17
+ Follow ["Uploading Changes" guide][1] on the site if you have some code to contribute.
18
+
19
+ All you should need to set up your development environment should be:
20
+
21
+ ~ % mkdir couchbase-ruby
22
+ ~ % cd couchbase-ruby
23
+ ~/couchbase-ruby % repo init -u git://github.com/trondn/manifests.git -m ruby.xml
24
+ ~/couchbase-ruby % repo sync
25
+ ~/couchbase-ruby % repo start my-branch-name --all
26
+ ~/couchbase-ruby % make
27
+
28
+ This will build the latest version of `libcouchbase`,
29
+ `couchbase-ruby-client` and `couchbase-ruby-client` libraries. You must
30
+ have a C and C++ compiler installed, automake, autoconf.
31
+
32
+ If you have to make any changes just commit them before you upload
33
+ them to gerrit with the following command:
34
+
35
+ ~/couchbase-ruby/client % repo upload
36
+
37
+ You might experience a problem trying to upload the patches if you've
38
+ selected a different login name at http://review.couchbase.org than
39
+ your login name. Don't worry, all you need to do is to add the
40
+ following to your ~/.gitconfig file:
41
+
42
+ [review "review.couchbase.org"]
43
+ username = YOURNAME
44
+
45
+ ## Contributing Using Plain Git
46
+
47
+ If you not so familiar with repo tool and its workflow there is
48
+ alternative way to do the same job. Lets assume you have installed
49
+ couchbase gem and libcouchbase from official packages and would you to
50
+ contribute to couchbase-client gem only. Then you just need to complete
51
+ gerrit registration steps above and clone the source repository
52
+ (remember the repository on github.com is just a mirror):
53
+
54
+ ~ % git clone ssh://YOURNAME@review.couchbase.org:29418/couchbase-ruby-client.git
55
+
56
+ Install [`commit-msg` hook][2]:
57
+
58
+ ~/couchbase-ruby-client % scp -p -P 29418 YOURNAME@review.couchbase.org:hooks/commit-msg .git/hooks/
59
+
60
+ Make your changes and upload them for review:
61
+
62
+ ~/couchbase-ruby-client % git commit
63
+ ~/couchbase-ruby-client % git push origin HEAD:refs/for/master
64
+
65
+ If you need to fix or add something to your patch, do it and re-upload
66
+ the changes (all you need is to keep `Change-Id:` line the same to
67
+ allow gerrit to track the patch.
68
+
69
+ ~/couchbase-ruby-client % git commit --amend
70
+ ~/couchbase-ruby-client % git push origin HEAD:refs/for/master
71
+
72
+ Happy hacking!
73
+
74
+ [1]: http://review.couchbase.org/Documentation/user-upload.html
75
+ [2]: http://review.couchbase.org/Documentation/user-changeid.html
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in couchbase.gemspec
4
+ gemspec
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.
@@ -0,0 +1,3 @@
1
+ all:
2
+ $(MAKE) -C../.. ruby-client
3
+
@@ -0,0 +1,665 @@
1
+ # Couchbase Ruby Client
2
+
3
+ This is the official client library for use with Couchbase Server. There
4
+ are related libraries available:
5
+
6
+ * [couchbase-model][6] the ActiveModel implementation, git repository:
7
+ [https://github.com/couchbase/couchbase-ruby-model][7]
8
+
9
+ ## SUPPORT
10
+
11
+ If you find an issue, please file it in our [JIRA][1]. Also you are
12
+ always welcome on the `#libcouchbase` channel at [freenode.net IRC
13
+ servers][2]. Checkout [library overview][overview] and [API
14
+ documentation][api].
15
+
16
+
17
+ ## INSTALL
18
+
19
+ This gem depends [libcouchbase][3]. In most cases installing
20
+ libcouchbase doesn't take much effort.
21
+
22
+ ### MacOS (Homebrew)
23
+
24
+ $ brew install libcouchbase
25
+
26
+ The official homebrew repository contains only stable versions of
27
+ libvbucket and libcouchbase, if you need preview, take a look at
28
+ Couchbase's fork: https://github.com/couchbase/homebrew
29
+
30
+ $ brew install https://raw.github.com/couchbase/homebrew/preview/Library/Formula/libcouchbase.rb
31
+
32
+ ### Debian (Ubuntu)
33
+
34
+ Add the appropriate line to `/etc/apt/sources.list.d/couchbase.list` for
35
+ your OS release:
36
+
37
+ # Ubuntu 11.10 Oneiric Ocelot (Debian unstable)
38
+ deb http://packages.couchbase.com/ubuntu oneiric oneiric/main
39
+
40
+ # Ubuntu 10.04 Lucid Lynx (Debian stable or testing)
41
+ deb http://packages.couchbase.com/ubuntu lucid lucid/main
42
+
43
+ Import the Couchbase PGP key:
44
+
45
+ wget -O- http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add -
46
+
47
+ Then install them
48
+
49
+ $ sudo apt-get update && sudo apt-get install libcouchbase-dev
50
+
51
+ Again, if you need a preview of a future version, just use another repository in
52
+ your `couchbase.list`
53
+
54
+ # Ubuntu 11.10 Oneiric Ocelot (Debian unstable)
55
+ deb http://packages.couchbase.com/preview/ubuntu oneiric oneiric/main
56
+
57
+ # Ubuntu 10.04 Lucid Lynx (Debian stable or testing)
58
+ deb http://packages.couchbase.com/preview/ubuntu lucid lucid/main
59
+
60
+ ### Centos (Redhat and rpm-based systems)
61
+
62
+ Add these lines to /etc/yum.repos.d/couchbase.repo using the correct architecture
63
+
64
+ [couchbase]
65
+ name = Couchbase package repository
66
+ baseurl = http://packages.couchbase.com/rpm/5.5/i386
67
+
68
+ [couchbase]
69
+ name = Couchbase package repository
70
+ baseurl = http://packages.couchbase.com/rpm/5.5/x86_64
71
+
72
+ Then to install libcouchbase itself, run:
73
+
74
+ $ sudo yum update && sudo yum install libcouchbase-devel
75
+
76
+ We have preview repositories for RPMs too, use them if you want to try
77
+ the latest version of libcouchbase:
78
+
79
+ [couchbase]
80
+ name = Couchbase package repository
81
+ baseurl = http://packages.couchbase.com/preview/rpm/5.5/i386
82
+
83
+ [couchbase]
84
+ name = Couchbase package repository
85
+ baseurl = http://packages.couchbase.com/preview/rpm/5.5/x86_64
86
+
87
+ ### Windows
88
+
89
+ There are no additional dependencies for Windows systems. The gem carries
90
+ a prebuilt binary for it.
91
+
92
+ ### Couchbase gem
93
+
94
+ Now install the couchbase gem itself
95
+
96
+ $ gem install couchbase
97
+
98
+ The library verified with all major ruby versions: 1.8.7, 1.9.3, 2.0,
99
+ 2.1.
100
+
101
+ ## USAGE
102
+
103
+ First, you need to load the library:
104
+
105
+ require 'couchbase'
106
+
107
+ There are several ways to establish a new connection to Couchbase Server.
108
+ By default it uses `http://localhost:8091/pools/default/buckets/default`
109
+ as the endpoint. The client will automatically adjust configuration when
110
+ the cluster will rebalance its nodes when nodes are added or deleted
111
+ therefore this client is "smart".
112
+
113
+ c = Couchbase.connect
114
+
115
+ This is equivalent to following forms:
116
+
117
+ c = Couchbase.connect("http://localhost:8091/pools/default/buckets/default")
118
+ c = Couchbase.connect("http://localhost:8091/pools/default")
119
+ c = Couchbase.connect("http://localhost:8091")
120
+ c = Couchbase.connect(:hostname => "localhost")
121
+ c = Couchbase.connect(:hostname => "localhost", :port => 8091)
122
+ c = Couchbase.connect(:pool => "default", :bucket => "default")
123
+
124
+ The hash parameters take precedence on string URL.
125
+
126
+ If you worry about state of your nodes or not sure what node is alive,
127
+ you can pass the list of nodes and the library will iterate over it
128
+ until finds the working one. From that moment it won't use **your**
129
+ list, because node list from cluster config carries more detail.
130
+
131
+ c = Couchbase.connect(:bucket => "mybucket",
132
+ :node_list => ['example.com:8091', example.net'])
133
+
134
+ There is also a handy method `Couchbase.bucket` which uses thread local
135
+ storage to keep a reference to a connection. You can set the
136
+ connection options via `Couchbase.connection_options`:
137
+
138
+ Couchbase.connection_options = {:bucket => 'blog'}
139
+ Couchbase.bucket.name #=> "blog"
140
+ Couchbase.bucket.set("foo", "bar") #=> 3289400178357895424
141
+
142
+ The library supports both synchronous and asynchronous mode. In
143
+ asynchronous mode all operations will return control to caller
144
+ without blocking current thread. You can pass a block to the method and it
145
+ will be called with result when the operation will be completed. You
146
+ need to run the event loop once you've scheduled your operations:
147
+
148
+ c = Couchbase.connect
149
+ c.run do |conn|
150
+ conn.get("foo") {|ret| puts ret.value}
151
+ conn.set("bar", "baz")
152
+ end
153
+
154
+ The handlers could be nested
155
+
156
+ c.run do |conn|
157
+ conn.get("foo") do |ret|
158
+ conn.incr(ret.value, :initial => 0)
159
+ end
160
+ end
161
+
162
+ The asynchronous callback receives an instance of `Couchbase::Result` which
163
+ responds to several methods to figure out what was happened:
164
+
165
+ * `success?`. Returns `true` if operation succed.
166
+
167
+ * `error`. Returns `nil` or exception object (subclass of
168
+ `Couchbase::Error::Base`) if something went wrong.
169
+
170
+ * `key`
171
+
172
+ * `value`
173
+
174
+ * `flags`
175
+
176
+ * `cas`. The CAS version tag.
177
+
178
+ * `node`. Node address. This is used in the flush and stats commands.
179
+
180
+ * `operation`. The symbol, representing an operation.
181
+
182
+
183
+ To handle global errors in async mode `#on_error` callback should be
184
+ used. It can be set in following fashions:
185
+
186
+ c.on_error do |opcode, key, exc|
187
+ # ...
188
+ end
189
+
190
+ handler = lambda {|opcode, key, exc| }
191
+ c.on_error = handler
192
+
193
+ By default connections use `:quiet` mode. This mean it won't raise
194
+ exceptions when the given key does not exist:
195
+
196
+ c.get("missing-key") #=> nil
197
+
198
+ It could be useful when you are trying to make you code a bit efficient
199
+ by avoiding exception handling. (See `#add` and `#replace` operations).
200
+ You can turn on these exceptions by passing `:quiet => false` when you
201
+ are instantiating the connection or change corresponding attribute:
202
+
203
+ c.quiet = false
204
+ c.get("missing-key") #=> raise Couchbase::Error::NotFound
205
+ c.get("missing-key", :quiet => true) #=> nil
206
+
207
+ The library supports three different formats for representing values:
208
+
209
+ * `:document` (default) format supports most of ruby types which could
210
+ be mapped to JSON data (hashes, arrays, string, numbers). A future
211
+ version will be able to run map/reduce queries on the values in the
212
+ document form (hashes)
213
+
214
+ * `:plain` This format avoids any conversions to be applied to your
215
+ data, but your data should be passed as String. This is useful for
216
+ building custom algorithms or formats. For example to implement a set:
217
+ http://dustin.github.com/2011/02/17/memcached-set.html
218
+
219
+ * `:marshal` Use this format if you'd like to transparently serialize your
220
+ ruby object with standard `Marshal.dump` and `Marshal.load` methods
221
+
222
+ The couchbase API is the superset of [Memcached binary protocol][5], so
223
+ you can use its operations.
224
+
225
+ ### Get
226
+
227
+ val = c.get("foo")
228
+ val, flags, cas = c.get("foo", :extended => true)
229
+
230
+ Get and touch
231
+
232
+ val = c.get("foo", :ttl => 10)
233
+
234
+ Get multiple values. In quiet mode will put `nil` values on missing
235
+ positions:
236
+
237
+ vals = c.get("foo", "bar", "baz")
238
+ val_foo, val_bar, val_baz = c.get("foo", "bar", "baz")
239
+ c.run do
240
+ c.get("foo") do |ret|
241
+ ret.success?
242
+ ret.error
243
+ ret.key
244
+ ret.value
245
+ ret.flags
246
+ ret.cas
247
+ end
248
+ end
249
+
250
+ Get multiple values with extended information. The result will
251
+ represented by hash with tuples `[value, flags, cas]` as a value.
252
+
253
+ vals = c.get("foo", "bar", "baz", :extended => true)
254
+ vals.inspect #=> {"baz"=>["3", 0, 4784582192793125888],
255
+ "foo"=>["1", 0, 8835713818674332672],
256
+ "bar"=>["2", 0, 10805929834096100352]}
257
+
258
+ Hash-like syntax
259
+
260
+ c["foo"]
261
+ c["foo", "bar", "baz"]
262
+ c["foo", {:extended => true}]
263
+ c["foo", :extended => true] # for ruby 1.9.x only
264
+
265
+ ### Touch
266
+
267
+ c.touch("foo") # use :default_ttl
268
+ c.touch("foo", 10)
269
+ c.touch("foo", :ttl => 10)
270
+ c.touch("foo" => 10, "bar" => 20)
271
+ c.touch("foo" => 10, "bar" => 20){|key, success| }
272
+
273
+ ### Set
274
+
275
+ c.set("foo", "bar")
276
+ c.set("foo", "bar", :flags => 0x1000, :ttl => 30, :format => :plain)
277
+ c["foo"] = "bar"
278
+ c["foo", {:flags => 0x1000, :format => :plain}] = "bar"
279
+ c["foo", :flags => 0x1000] = "bar" # for ruby 1.9.x only
280
+ c.set("foo", "bar", :cas => 8835713818674332672)
281
+ c.set("foo", "bar"){|cas, key, operation| }
282
+
283
+ ### Add
284
+
285
+ The add command will fail if the key already exists. It accepts the same
286
+ options as set command above.
287
+
288
+ c.add("foo", "bar")
289
+ c.add("foo", "bar", :flags => 0x1000, :ttl => 30, :format => :plain)
290
+
291
+ ### Replace
292
+
293
+ The replace command will fail if the key already exists. It accepts the same
294
+ options as set command above.
295
+
296
+ c.replace("foo", "bar")
297
+
298
+ ### Prepend/Append
299
+
300
+ These commands are meaningful when you are using the `:plain` value format,
301
+ because the concatenation is performed by server which has no idea how
302
+ to merge to JSON values or values in ruby Marshal format. You may receive
303
+ an `Couchbase::Error::ValueFormat` error.
304
+
305
+ c.set("foo", "world")
306
+ c.append("foo", "!")
307
+ c.prepend("foo", "Hello, ")
308
+ c.get("foo") #=> "Hello, world!"
309
+
310
+ ### Increment/Decrement
311
+
312
+ These commands increment the value assigned to the key. It will raise
313
+ Couchbase::Error::DeltaBadval if the delta or value is not a number.
314
+
315
+ c.set("foo", 1)
316
+ c.incr("foo") #=> 2
317
+ c.incr("foo", :delta => 2) #=> 4
318
+ c.incr("foo", 4) #=> 8
319
+ c.incr("foo", -1) #=> 7
320
+ c.incr("foo", -100) #=> 0
321
+ c.run do
322
+ c.incr("foo") do |ret|
323
+ ret.success?
324
+ ret.value
325
+ ret.cas
326
+ end
327
+ end
328
+
329
+ c.set("foo", 10)
330
+ c.decr("foo", 1) #=> 9
331
+ c.decr("foo", 100) #=> 0
332
+ c.run do
333
+ c.decr("foo") do |ret|
334
+ ret.success?
335
+ ret.value
336
+ ret.cas
337
+ end
338
+ end
339
+
340
+ c.incr("missing1", :initial => 10) #=> 10
341
+ c.incr("missing1", :initial => 10) #=> 11
342
+ c.incr("missing2", :create => true) #=> 0
343
+ c.incr("missing2", :create => true) #=> 1
344
+
345
+ Note that it isn't the same as increment/decrement in ruby. A
346
+ Couchbase increment is atomic on a distributed system. The
347
+ Ruby incement could ovewrite intermediate values with multiple
348
+ clients, as shown with following `set` operation:
349
+
350
+ c["foo"] = 10
351
+ c["foo"] -= 20 #=> -10
352
+
353
+ ### Delete
354
+
355
+ c.delete("foo")
356
+ c.delete("foo", :cas => 8835713818674332672)
357
+ c.delete("foo", 8835713818674332672)
358
+ c.run do
359
+ c.delete do |ret|
360
+ ret.success?
361
+ ret.key
362
+ end
363
+ end
364
+
365
+ ### Flush
366
+
367
+ Flush the items in the cluster.
368
+
369
+ c.flush
370
+ c.run do
371
+ c.flush do |ret|
372
+ ret.success?
373
+ ret.node
374
+ end
375
+ end
376
+
377
+ ### Stats
378
+
379
+ Return statistics from each node in the cluster
380
+
381
+ c.stats
382
+ c.stats(:memory)
383
+ c.run do
384
+ c.stats do |ret|
385
+ ret.success?
386
+ ret.node
387
+ ret.key
388
+ ret.value
389
+ end
390
+ end
391
+
392
+ The result is represented as a hash with the server node address as
393
+ the key and stats as key-value pairs.
394
+
395
+ {
396
+ "threads"=>
397
+ {
398
+ "172.16.16.76:12008"=>"4",
399
+ "172.16.16.76:12000"=>"4",
400
+ # ...
401
+ },
402
+ "connection_structures"=>
403
+ {
404
+ "172.16.16.76:12008"=>"22",
405
+ "172.16.16.76:12000"=>"447",
406
+ # ...
407
+ },
408
+ "ep_max_txn_size"=>
409
+ {
410
+ "172.16.16.76:12008"=>"1000",
411
+ "172.16.16.76:12000"=>"1000",
412
+ # ...
413
+ },
414
+ # ...
415
+ }
416
+
417
+ ### Timers
418
+
419
+ It is possible to create timers to implement general purpose timeouts.
420
+ Note that timers are using microseconds for time intervals. For example,
421
+ following examples increment the keys value five times with 0.5 second
422
+ interval:
423
+
424
+ c.set("foo", 100)
425
+ n = 1
426
+ c.run do
427
+ c.create_periodic_timer(500000) do |tm|
428
+ c.incr("foo") do
429
+ if n == 5
430
+ tm.cancel
431
+ else
432
+ n += 1
433
+ end
434
+ end
435
+ end
436
+ end
437
+
438
+ ### Views (Map/Reduce queries)
439
+
440
+ If you store structured data, they will be treated as documents and you
441
+ can handle them in map/reduce function from Couchbase Views. For example,
442
+ store a couple of posts using memcached API:
443
+
444
+ c['biking'] = {:title => 'Biking',
445
+ :body => 'My biggest hobby is mountainbiking. The other day...',
446
+ :date => '2009/01/30 18:04:11'}
447
+ c['bought-a-cat'] = {:title => 'Bought a Cat',
448
+ :body => 'I went to the the pet store earlier and brought home a little kitty...',
449
+ :date => '2009/01/30 20:04:11'}
450
+ c['hello-world'] = {:title => 'Hello World',
451
+ :body => 'Well hello and welcome to my new blog...',
452
+ :date => '2009/01/15 15:52:20'}
453
+
454
+ Now let's create design doc with sample view and save it in file
455
+ 'blog.json':
456
+
457
+ {
458
+ "_id": "_design/blog",
459
+ "language": "javascript",
460
+ "views": {
461
+ "recent_posts": {
462
+ "map": "function(doc){if(doc.date && doc.title){emit(doc.date, doc.title);}}"
463
+ }
464
+ }
465
+ }
466
+
467
+ This design document could be loaded into the database like this (also you can
468
+ pass the ruby Hash or String with JSON encoded document):
469
+
470
+ c.save_design_doc(File.open('blog.json'))
471
+
472
+ To execute view you need to fetch it from design document `_design/blog`:
473
+
474
+ blog = c.design_docs['blog']
475
+ blog.views #=> ["recent_posts"]
476
+ blog.recent_posts #=> [#<Couchbase::ViewRow:9855800 @id="hello-world" @key="2009/01/15 15:52:20" @value="Hello World" @doc=nil @meta={} @views=[]>, ...]
477
+
478
+ The gem uses a streaming parser to access view results so you can iterate them
479
+ easily. If your code doesn't keep links to the documents the GC might free
480
+ them as soon as it decides they are unreachable, because the parser doesn't
481
+ store global JSON tree.
482
+
483
+ blog.recent_posts.each do |doc|
484
+ # do something
485
+ # with doc object
486
+ doc.key # gives the key argument of the emit()
487
+ doc.value # gives the value argument of the emit()
488
+ end
489
+
490
+ Load with documents
491
+
492
+ blog.recent_posts(:include_docs => true).each do |doc|
493
+ doc.doc # gives the document which emitted the item
494
+ doc['date'] # gives the argument of the underlying document
495
+ end
496
+
497
+
498
+ You can also use Enumerator to iterate view results
499
+
500
+ require 'date'
501
+ posts_by_date = Hash.new{|h,k| h[k] = []}
502
+ enum = c.recent_posts(:include_docs => true).each # request hasn't issued yet
503
+ enum.inject(posts_by_date) do |acc, doc|
504
+ acc[date] = Date.strptime(doc['date'], '%Y/%m/%d')
505
+ acc
506
+ end
507
+
508
+ Couchbase Server could generate errors during view execution with
509
+ `200 OK` and partial results. By default the library raises exception as
510
+ soon as errors detected in the result stream, but you can define the
511
+ callback `on_error` to intercept these errors and do something more
512
+ useful.
513
+
514
+ view = blog.recent_posts(:include_docs => true)
515
+ logger = Logger.new(STDOUT)
516
+
517
+ view.on_error do |from, reason|
518
+ logger.warn("#{view.inspect} received the error '#{reason}' from #{from}")
519
+ end
520
+
521
+ posts = view.each do |doc|
522
+ # do something
523
+ # with doc object
524
+ end
525
+
526
+ Note that errors object in view results usually goes *after* the rows,
527
+ so you will likely receive a number of view results successfully before
528
+ the error is detected.
529
+
530
+ ## Engines
531
+
532
+ As far as couchbase gem uses [libcouchbase][8] as the backend, you can
533
+ choose from several asynchronous IO options:
534
+
535
+ * `:default` this one is used by default and implemented as the part
536
+ of the ruby extensions (this mean you don't need any dependencies
537
+ apart from libcouchbase2-core and libcouchbase-dev to build and use
538
+ it). This engine honours ruby GVL, so when it comes to waiting for
539
+ IO operations from kernel it release the GVL allowing interpreter to
540
+ run your code. This technique isn't available on windows, but down't
541
+ worry `:default` engine still accessible and will pick up statically
542
+ linked on that platform `:libevent` engine.
543
+
544
+ * `:libev` and `:libevent`, these two engines require installed
545
+ libcouchbase2-libev and libcouchbase2-libevent packages
546
+ correspondingly. Currently they aren't so friendly to GVL but still
547
+ useful.
548
+
549
+ * `:eventmachine` engine. From version 1.2.2 it is possible to use
550
+ great [EventMachine][9] library as underlying IO backend and
551
+ integrate couchbase gem to your current asynchronous application.
552
+ This engine will be only accessible on the MRI ruby 1.9+. Checkout
553
+ simple example of usage:
554
+
555
+ require 'eventmachine'
556
+ require 'couchbase'
557
+
558
+ EM.epoll = true if EM.epoll?
559
+ EM.kqueue = true if EM.kqueue?
560
+ EM.run do
561
+ con = Couchbase.connect :engine => :eventmachine, :async => true
562
+ con.on_connect do |res|
563
+ puts "connected: #{res.inspect}"
564
+ if res.success?
565
+ con.set("emfoo", "bar") do |res|
566
+ puts "set: #{res.inspect}"
567
+ con.get("emfoo") do |res|
568
+ puts "get: #{res.inspect}"
569
+ EM.stop
570
+ end
571
+ end
572
+ else
573
+ EM.stop
574
+ end
575
+ end
576
+ end
577
+
578
+ ## HACKING
579
+
580
+ Clone the repository. For starters, you can use github mirror, but
581
+ make sure you have read and understand [CONTRIBUTING.markdown][10] if
582
+ you are going to send us patches.
583
+
584
+ $ git clone git://github.com/couchbase/couchbase-ruby-client.git
585
+ $ cd couchbase-ruby-client
586
+
587
+ Install all development dependencies. You can use any ruby version
588
+ since 1.8.7, but make sure your changes work at least on major
589
+ releases (1.8.7, 1.9.3, 2.0.0 and 2.1.0 at the moment):
590
+
591
+ $ gem install bundler
592
+ $ bundle install
593
+
594
+ Don't forget to write the tests. You can find examples in the `tests/`
595
+ directory. To run tests with a mock just compile extension and run the
596
+ `test` task, it will download a test mock of couchbase cluster as a
597
+ part of the process (the mock is generally slower, but easier to
598
+ setup):
599
+
600
+ $ rake compile test
601
+
602
+ If you have real Couchbase server installed somewhere, you can pass
603
+ its address using environment variable `COUCHBASE_SERVER` like this:
604
+
605
+ $ COUCHBASE_SERVER=localhost:8091 rake compile test
606
+
607
+ And finally, you can package the gem with your awesome changes. For
608
+ UNIX-like systems a regular source-based package will be enough, so the
609
+ command below will produce `pkg/couchbase-VERSION.gem`, where
610
+ `VERSION` is the current version from file `lib/couchbase/version.rb`:
611
+
612
+ $ rake package
613
+
614
+ The Windows operating system usually doesn't have a build environment
615
+ installed. This is why we are cross-compiling blobs for Windows from
616
+ UNIX-like boxes. To do it you need to install mingw and the
617
+ [rake-compiler][11] and then build a variety of ruby versions currently
618
+ supported on Windows. An example config looks like this:
619
+
620
+ $ rake-compiler update-config
621
+ Updating /home/avsej/.rake-compiler/config.yml
622
+ Found Ruby version 1.8.7 for platform i386-mingw32 (/home/avsej/.rake-compiler/ruby/i686-w64-mingw32/ruby-1.8.7-p374/lib/ruby/1.8/i386-mingw32/rbconfig.rb)
623
+ Found Ruby version 1.9.3 for platform i386-mingw32 (/home/avsej/.rake-compiler/ruby/i686-w64-mingw32/ruby-1.9.3-p448/lib/ruby/1.9.1/i386-mingw32/rbconfig.rb)
624
+ Found Ruby version 2.0.0 for platform i386-mingw32 (/home/avsej/.rake-compiler/ruby/i686-w64-mingw32/ruby-2.0.0-p247/lib/ruby/2.0.0/i386-mingw32/rbconfig.rb)
625
+ Found Ruby version 2.1.0 for platform i386-mingw32 (/home/avsej/.rake-compiler/ruby/i686-w64-mingw32/ruby-2.1.0/lib/ruby/2.1.0/i386-mingw32/rbconfig.rb)
626
+ Found Ruby version 1.9.3 for platform x64-mingw32 (/home/avsej/.rake-compiler/ruby/x86_64-w64-mingw32/ruby-1.9.3-p448/lib/ruby/1.9.1/x64-mingw32/rbconfig.rb)
627
+ Found Ruby version 2.0.0 for platform x64-mingw32 (/home/avsej/.rake-compiler/ruby/x86_64-w64-mingw32/ruby-2.0.0-p247/lib/ruby/2.0.0/x64-mingw32/rbconfig.rb)
628
+ Found Ruby version 2.1.0 for platform x64-mingw32 (/home/avsej/.rake-compiler/ruby/x86_64-w64-mingw32/ruby-2.1.0/lib/ruby/2.1.0/x64-mingw32/rbconfig.rb)
629
+
630
+ To install all versions needed for `rake package:windows` use these
631
+ commands:
632
+
633
+ $ rake-compiler cross-ruby HOST=i386-mingw32 VERSION=1.8.7-p374
634
+ $ rake-compiler cross-ruby HOST=i386-mingw32 VERSION=1.9.3-p448
635
+ $ rake-compiler cross-ruby HOST=i386-mingw32 VERSION=2.0.0-p247
636
+ $ rake-compiler cross-ruby HOST=i386-mingw32 VERSION=2.1.0
637
+ $ rake-compiler cross-ruby HOST=x64-mingw32 VERSION=1.9.3-p448
638
+ $ rake-compiler cross-ruby HOST=x64-mingw32 VERSION=2.0.0-p247
639
+ $ rake-compiler cross-ruby HOST=x64-mingw32 VERSION=2.1.0
640
+
641
+ Before you build, check relevant ruby and libcouchbase versions in
642
+ `tasks/compile.rake`. After that you can run the `package:windows`
643
+ task and you will find all artifacts in `pkg/` directory:
644
+
645
+ $ rake package:windows
646
+ $ ls -1 pkg/*.gem
647
+ pkg/couchbase-1.3.4.gem
648
+ pkg/couchbase-1.3.4-x64-mingw32.gem
649
+ pkg/couchbase-1.3.4-x86-mingw32.gem
650
+
651
+
652
+ [api]: http://www.couchbase.com/autodocs/couchbase-ruby-client-1.3.4/index.html
653
+ [overview]: http://docs.couchbase.com/couchbase-sdk-ruby-1.3/index.html
654
+ [1]: http://couchbase.com/issues/browse/RCBC
655
+ [2]: http://freenode.net/irc_servers.shtml
656
+ [3]: http://www.couchbase.com/develop/c/current
657
+ [4]: https://github.com/mxcl/homebrew/pulls/avsej
658
+ [5]: http://code.google.com/p/memcached/wiki/BinaryProtocolRevamped
659
+ [6]: https://rubygems.org/gems/couchbase-model
660
+ [7]: https://github.com/couchbase/couchbase-ruby-model
661
+ [8]: http://www.couchbase.com/develop/c/current
662
+ [9]: http://rubygems.org/gems/eventmachine
663
+ [10]: https://github.com/couchbase/couchbase-ruby-client/blob/master/CONTRIBUTING.markdown
664
+ [11]: https://github.com/luislavena/rake-compiler
665
+