riak-client-noenc 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +42 -0
  4. data/.rspec +1 -0
  5. data/Gemfile +17 -0
  6. data/Guardfile +20 -0
  7. data/LICENSE.md +16 -0
  8. data/README.markdown +640 -0
  9. data/RELEASE_NOTES.md +392 -0
  10. data/Rakefile +119 -0
  11. data/lib/riak.rb +22 -0
  12. data/lib/riak/bucket.rb +297 -0
  13. data/lib/riak/bucket_properties.rb +74 -0
  14. data/lib/riak/bucket_type.rb +77 -0
  15. data/lib/riak/bucket_typed/bucket.rb +121 -0
  16. data/lib/riak/client.rb +433 -0
  17. data/lib/riak/client/beefcake/bucket_properties_operator.rb +178 -0
  18. data/lib/riak/client/beefcake/crdt/counter_loader.rb +18 -0
  19. data/lib/riak/client/beefcake/crdt/map_loader.rb +64 -0
  20. data/lib/riak/client/beefcake/crdt/set_loader.rb +18 -0
  21. data/lib/riak/client/beefcake/crdt_loader.rb +84 -0
  22. data/lib/riak/client/beefcake/crdt_operator.rb +223 -0
  23. data/lib/riak/client/beefcake/footer +4 -0
  24. data/lib/riak/client/beefcake/header +6 -0
  25. data/lib/riak/client/beefcake/message_codes.rb +89 -0
  26. data/lib/riak/client/beefcake/message_overlay.rb +87 -0
  27. data/lib/riak/client/beefcake/messages.rb +772 -0
  28. data/lib/riak/client/beefcake/object_methods.rb +112 -0
  29. data/lib/riak/client/beefcake/protocol.rb +105 -0
  30. data/lib/riak/client/beefcake/socket.rb +260 -0
  31. data/lib/riak/client/beefcake_protobuffs_backend.rb +538 -0
  32. data/lib/riak/client/decaying.rb +36 -0
  33. data/lib/riak/client/feature_detection.rb +120 -0
  34. data/lib/riak/client/instrumentation.rb +19 -0
  35. data/lib/riak/client/node.rb +49 -0
  36. data/lib/riak/client/protobuffs_backend.rb +143 -0
  37. data/lib/riak/client/search.rb +27 -0
  38. data/lib/riak/client/yokozuna.rb +52 -0
  39. data/lib/riak/conflict.rb +13 -0
  40. data/lib/riak/core_ext.rb +7 -0
  41. data/lib/riak/core_ext/blank.rb +53 -0
  42. data/lib/riak/core_ext/deep_dup.rb +13 -0
  43. data/lib/riak/core_ext/extract_options.rb +7 -0
  44. data/lib/riak/core_ext/json.rb +15 -0
  45. data/lib/riak/core_ext/slice.rb +18 -0
  46. data/lib/riak/core_ext/stringify_keys.rb +10 -0
  47. data/lib/riak/core_ext/symbolize_keys.rb +10 -0
  48. data/lib/riak/core_ext/to_param.rb +31 -0
  49. data/lib/riak/counter.rb +101 -0
  50. data/lib/riak/crdt.rb +21 -0
  51. data/lib/riak/crdt/base.rb +183 -0
  52. data/lib/riak/crdt/batch_counter.rb +19 -0
  53. data/lib/riak/crdt/batch_map.rb +41 -0
  54. data/lib/riak/crdt/counter.rb +82 -0
  55. data/lib/riak/crdt/inner_counter.rb +81 -0
  56. data/lib/riak/crdt/inner_flag.rb +42 -0
  57. data/lib/riak/crdt/inner_map.rb +75 -0
  58. data/lib/riak/crdt/inner_register.rb +26 -0
  59. data/lib/riak/crdt/inner_set.rb +102 -0
  60. data/lib/riak/crdt/map.rb +121 -0
  61. data/lib/riak/crdt/operation.rb +19 -0
  62. data/lib/riak/crdt/set.rb +166 -0
  63. data/lib/riak/crdt/typed_collection.rb +181 -0
  64. data/lib/riak/encoding.rb +6 -0
  65. data/lib/riak/errors/backend_creation.rb +9 -0
  66. data/lib/riak/errors/base.rb +9 -0
  67. data/lib/riak/errors/connection_error.rb +50 -0
  68. data/lib/riak/errors/crdt_error.rb +38 -0
  69. data/lib/riak/errors/failed_request.rb +58 -0
  70. data/lib/riak/errors/protobuffs_error.rb +11 -0
  71. data/lib/riak/errors/search_error.rb +35 -0
  72. data/lib/riak/i18n.rb +7 -0
  73. data/lib/riak/index_collection.rb +71 -0
  74. data/lib/riak/instrumentation.rb +6 -0
  75. data/lib/riak/json.rb +52 -0
  76. data/lib/riak/link.rb +96 -0
  77. data/lib/riak/list_buckets.rb +28 -0
  78. data/lib/riak/locale/en.yml +107 -0
  79. data/lib/riak/locale/fr.yml +51 -0
  80. data/lib/riak/map_reduce.rb +295 -0
  81. data/lib/riak/map_reduce/filter_builder.rb +103 -0
  82. data/lib/riak/map_reduce/phase.rb +98 -0
  83. data/lib/riak/map_reduce/results.rb +49 -0
  84. data/lib/riak/map_reduce_error.rb +7 -0
  85. data/lib/riak/multiget.rb +122 -0
  86. data/lib/riak/preflist_item.rb +7 -0
  87. data/lib/riak/rcontent.rb +173 -0
  88. data/lib/riak/robject.rb +222 -0
  89. data/lib/riak/search.rb +11 -0
  90. data/lib/riak/search/index.rb +87 -0
  91. data/lib/riak/search/query.rb +141 -0
  92. data/lib/riak/search/result_collection.rb +144 -0
  93. data/lib/riak/search/result_document.rb +129 -0
  94. data/lib/riak/search/schema.rb +65 -0
  95. data/lib/riak/secondary_index.rb +81 -0
  96. data/lib/riak/serializers.rb +73 -0
  97. data/lib/riak/stamp.rb +77 -0
  98. data/lib/riak/util/escape.rb +80 -0
  99. data/lib/riak/util/tcp_socket_extensions.rb +58 -0
  100. data/lib/riak/util/translation.rb +18 -0
  101. data/lib/riak/version.rb +3 -0
  102. data/lib/riak/walk_spec.rb +145 -0
  103. data/spec/failover/failover.rb +59 -0
  104. data/spec/fixtures/bitcask.txt +25 -0
  105. data/spec/fixtures/cat.jpg +0 -0
  106. data/spec/fixtures/multipart-basic-conflict.txt +15 -0
  107. data/spec/fixtures/multipart-blank.txt +7 -0
  108. data/spec/fixtures/multipart-mapreduce.txt +10 -0
  109. data/spec/fixtures/multipart-with-body.txt +16 -0
  110. data/spec/fixtures/multipart-with-marked-tombstones.txt +17 -0
  111. data/spec/fixtures/multipart-with-unmarked-tombstone.txt +16 -0
  112. data/spec/fixtures/server.cert.crt +15 -0
  113. data/spec/fixtures/server.cert.key +15 -0
  114. data/spec/fixtures/test.pem +1 -0
  115. data/spec/fixtures/yz_schema_template.xml +18 -0
  116. data/spec/integration/riak/bucket_types_spec.rb +270 -0
  117. data/spec/integration/riak/conflict_resolution_spec.rb +96 -0
  118. data/spec/integration/riak/counters_spec.rb +36 -0
  119. data/spec/integration/riak/crdt/configuration_spec.rb +37 -0
  120. data/spec/integration/riak/crdt_search_spec.rb +176 -0
  121. data/spec/integration/riak/crdt_spec.rb +250 -0
  122. data/spec/integration/riak/crdt_validation/map_spec.rb +63 -0
  123. data/spec/integration/riak/crdt_validation/set_spec.rb +122 -0
  124. data/spec/integration/riak/preflist_spec.rb +31 -0
  125. data/spec/integration/riak/properties_spec.rb +69 -0
  126. data/spec/integration/riak/protobuffs/interrupted_request_spec.rb +33 -0
  127. data/spec/integration/riak/protobuffs_backends_spec.rb +40 -0
  128. data/spec/integration/riak/search_spec.rb +104 -0
  129. data/spec/integration/riak/secondary_index_spec.rb +72 -0
  130. data/spec/integration/riak/security_spec.rb +100 -0
  131. data/spec/integration/riak/threading_spec.rb +150 -0
  132. data/spec/integration/yokozuna/index_spec.rb +61 -0
  133. data/spec/integration/yokozuna/queries_spec.rb +115 -0
  134. data/spec/integration/yokozuna/schema_spec.rb +49 -0
  135. data/spec/riak/beefcake_protobuffs_backend/bucket_properties_operator_spec.rb +247 -0
  136. data/spec/riak/beefcake_protobuffs_backend/crdt_operator_spec.rb +222 -0
  137. data/spec/riak/beefcake_protobuffs_backend/object_methods_spec.rb +23 -0
  138. data/spec/riak/beefcake_protobuffs_backend/protocol_spec.rb +189 -0
  139. data/spec/riak/beefcake_protobuffs_backend_spec.rb +162 -0
  140. data/spec/riak/bucket_properties_spec.rb +135 -0
  141. data/spec/riak/bucket_spec.rb +275 -0
  142. data/spec/riak/bucket_type_spec.rb +50 -0
  143. data/spec/riak/bucket_typed/bucket_spec.rb +62 -0
  144. data/spec/riak/client_spec.rb +246 -0
  145. data/spec/riak/core_ext/to_param_spec.rb +15 -0
  146. data/spec/riak/counter_spec.rb +122 -0
  147. data/spec/riak/crdt/counter_spec.rb +55 -0
  148. data/spec/riak/crdt/inner_counter_spec.rb +21 -0
  149. data/spec/riak/crdt/inner_flag_spec.rb +39 -0
  150. data/spec/riak/crdt/inner_map_spec.rb +47 -0
  151. data/spec/riak/crdt/inner_register_spec.rb +40 -0
  152. data/spec/riak/crdt/inner_set_spec.rb +33 -0
  153. data/spec/riak/crdt/map_spec.rb +78 -0
  154. data/spec/riak/crdt/set_spec.rb +61 -0
  155. data/spec/riak/crdt/shared_examples.rb +74 -0
  156. data/spec/riak/crdt/typed_collection_spec.rb +225 -0
  157. data/spec/riak/escape_spec.rb +72 -0
  158. data/spec/riak/feature_detection_spec.rb +77 -0
  159. data/spec/riak/index_collection_spec.rb +53 -0
  160. data/spec/riak/instrumentation_spec.rb +124 -0
  161. data/spec/riak/link_spec.rb +85 -0
  162. data/spec/riak/list_buckets_spec.rb +41 -0
  163. data/spec/riak/map_reduce/filter_builder_spec.rb +32 -0
  164. data/spec/riak/map_reduce/phase_spec.rb +142 -0
  165. data/spec/riak/map_reduce_spec.rb +434 -0
  166. data/spec/riak/multiget_spec.rb +81 -0
  167. data/spec/riak/node_spec.rb +26 -0
  168. data/spec/riak/robject_spec.rb +496 -0
  169. data/spec/riak/search/index_spec.rb +72 -0
  170. data/spec/riak/search/query_spec.rb +88 -0
  171. data/spec/riak/search/result_collection_spec.rb +89 -0
  172. data/spec/riak/search/result_document_spec.rb +106 -0
  173. data/spec/riak/search/schema_spec.rb +63 -0
  174. data/spec/riak/search_spec.rb +107 -0
  175. data/spec/riak/secondary_index_spec.rb +225 -0
  176. data/spec/riak/serializers_spec.rb +121 -0
  177. data/spec/riak/stamp_spec.rb +54 -0
  178. data/spec/riak/walk_spec_spec.rb +203 -0
  179. data/spec/spec_helper.rb +66 -0
  180. data/spec/support/certs/README.md +13 -0
  181. data/spec/support/certs/ca.crt +21 -0
  182. data/spec/support/certs/client.crl +13 -0
  183. data/spec/support/certs/client.crt +94 -0
  184. data/spec/support/certs/client.csr +18 -0
  185. data/spec/support/certs/client.key +27 -0
  186. data/spec/support/certs/empty_ca.crt +21 -0
  187. data/spec/support/certs/server.crl +13 -0
  188. data/spec/support/certs/server.crt +94 -0
  189. data/spec/support/certs/server.key +27 -0
  190. data/spec/support/crdt_search_config.rb +112 -0
  191. data/spec/support/crdt_search_fixtures.rb +42 -0
  192. data/spec/support/integration_setup.rb +10 -0
  193. data/spec/support/search_config.rb +83 -0
  194. data/spec/support/search_corpus_setup.rb +39 -0
  195. data/spec/support/test_client.rb +46 -0
  196. data/spec/support/test_client.yml.example +10 -0
  197. data/spec/support/unified_backend_examples.rb +380 -0
  198. data/spec/support/version_filter.rb +12 -0
  199. data/spec/support/wait_until.rb +20 -0
  200. metadata +511 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 482350f4252e6bbc15ad2947884a62c81bd44615
4
+ data.tar.gz: e577ff4be7e511f5b2556ae8c443f52e5f8e7986
5
+ SHA512:
6
+ metadata.gz: 24a7f2a413fd57acd6875594a71b768b210d2dc5ad1a081a4283c06fa4076df8ec3a1ad21a2a222edd490ad33ec15d9e90729750ed11adaca9c63c4b7556b738
7
+ data.tar.gz: 5b8a4b9315a9a74289559571b6c3c51aef685ba5e0a70858eefe668c2c48eefd226eb9da4328334a37f3e34eab526d8245f6bc19e87c512e7a0d7dcd8c3fa463
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,42 @@
1
+ ## NOTE: This file must be manually kept in sync with the gemspec, but
2
+ ## should not normally need to be modified unless new top-level files
3
+ ## or directory trees are being added.
4
+
5
+ ## MAC OS
6
+ .DS_Store
7
+
8
+ ## TEXTMATE
9
+ *.tmproj
10
+ tmtags
11
+
12
+ ## EMACS
13
+ *~
14
+ \#*
15
+ .\#*
16
+
17
+ ## VIM
18
+ *.swp
19
+
20
+ ## PROJECT::GENERAL
21
+ coverage
22
+ rdoc
23
+ pkg
24
+
25
+ ## PROJECT::SPECIFIC
26
+ _notes
27
+ doc
28
+ .yardoc
29
+ .bundle
30
+ spec/support/test_client.yml
31
+ Gemfile.lock
32
+ **/bin
33
+ *.rbc
34
+ .rvmrc
35
+
36
+ .riaktest
37
+ **/.riaktest
38
+ vendor/erlang
39
+ vendor/riak
40
+ .ruby-version
41
+ tmp
42
+ tags
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :guard do
6
+ gem 'guard-rspec'
7
+ gem 'rb-fsevent'
8
+ gem 'terminal-notifier-guard'
9
+ end
10
+
11
+ platforms :mri do
12
+ gem 'yajl-ruby'
13
+ end
14
+
15
+ platforms :jruby, :rbx do
16
+ gem 'json'
17
+ end
data/Guardfile ADDED
@@ -0,0 +1,20 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec', all_after_pass: true, all_on_start: true do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/riak/(.+)\.rb$}) { |m| "spec/riak/#{m[1]}_spec.rb" }
15
+ watch(%r{^lib/riak/client/}) { 'spec/riak/beefcake_protobuffs_backend' }
16
+ watch('spec/spec_helper.rb') { "spec" }
17
+
18
+ watch(/^spec\/integration/) { 'spec:integration' }
19
+ end
20
+
data/LICENSE.md ADDED
@@ -0,0 +1,16 @@
1
+ Copyright 2010-2011 Sean Cribbs and Basho Technologies, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
14
+
15
+ All of the files in this project are under the project-wide license
16
+ unless they are otherwise marked.
data/README.markdown ADDED
@@ -0,0 +1,640 @@
1
+ # Riak Ruby Client (riak-client)
2
+
3
+ `riak-client` is a rich Ruby client/toolkit for Riak, Basho's
4
+ distributed database that contains a basic wrapper around typical
5
+ operations, including bucket manipulation, object CRUD, link-walking,
6
+ and map-reduce.
7
+
8
+ Exhaustive documentation is available at
9
+ http://basho.github.io/riak-ruby-client/ , and API documentation can be
10
+ read at http://www.rubydoc.info/gems/riak-client/frames .
11
+
12
+ ## Dependencies
13
+
14
+ Ruby 1.9.3, 2.0, 2.1, and 2.2 are supported. JRuby in 1.9 and 2.0 modes are
15
+ also supported. `riak-client` is not compatible with Ruby 1.8.
16
+
17
+ In JRuby 1.7.13, OCSP validation is absent, and CRL validation always
18
+ fails. [This issue is being tracked][1] and this document will be updated when
19
+ it is fixed. Additionally, client certificate authentication doesn't work in
20
+ JRuby. [This issue is also being tracked][2], and this document will be updated
21
+ when it works.
22
+
23
+ [1]: https://github.com/jruby/jruby-openssl/issues/5
24
+ [2]: https://github.com/basho/riak_api/issues/65
25
+
26
+ `riak-client` requires beefcake, cert_validator, i18n, innertube, and
27
+ multi_json.
28
+
29
+ Development dependencies are handled with bundler. Install bundler
30
+ (`gem install bundler`) and run this command to get started:
31
+
32
+ ```bash
33
+ $ bundle install
34
+ ```
35
+
36
+ Run the RSpec suite using `bundle exec`:
37
+
38
+ ```bash
39
+ $ bundle exec rake
40
+ ```
41
+
42
+ ## Basic Example
43
+
44
+ ```ruby
45
+ require 'riak'
46
+
47
+ # Create a client interface
48
+ client = Riak::Client.new
49
+
50
+ # Create a client that uses secure Protocol Buffers
51
+ client = Riak::Client.new(authentication: {
52
+ # certificate authority to validate the server cert
53
+ ca_file: '/home/zedo/ca.crt',
54
+
55
+ # username, required
56
+ user: 'zedo',
57
+
58
+ # password for password-based authentication
59
+ password: 'catnip',
60
+
61
+ # client-cert authentication parameters support filenames,
62
+ # OpenSSL-compatible string data, or properly initialized
63
+ # OpenSSL objects
64
+ client_ca: '/home/zedo/ca.crt',
65
+ cert: File.read '/home/zedo/zedo.crt',
66
+ key: OpenSSL::PKey::RSA.new(File.read '/home/zedo/zedo.key')
67
+ })
68
+
69
+ # Automatically balance between multiple nodes
70
+ client = Riak::Client.new(:nodes => [
71
+ {:host => '10.0.0.1'},
72
+ {:host => '10.0.0.2', :pb_port => 1234},
73
+ {:host => '10.0.0.3', :pb_port => 5678}
74
+ ])
75
+
76
+ # Retrieve a bucket
77
+ bucket = client.bucket("doc") # a Riak::Bucket
78
+
79
+ # Get an object from the bucket
80
+ object = bucket.get_or_new("index.html") # a Riak::RObject
81
+
82
+ # Change the object's data and save
83
+ object.raw_data = "<html><body>Hello, world!</body></html>"
84
+ object.content_type = "text/html"
85
+ object.store
86
+
87
+ # Reload an object you already have
88
+ object.reload # Works if you have the key and vclock, using conditional GET
89
+ object.reload :force => true # Reloads whether you have the vclock or not
90
+
91
+ # Access more like a hash, client[bucket][key]
92
+ client['doc']['index.html'] # the Riak::RObject
93
+
94
+ # Create a new object
95
+ new_one = Riak::RObject.new(bucket, "application.js")
96
+ new_one.content_type = "application/javascript" # You must set the content type.
97
+ new_one.raw_data = "alert('Hello, World!')"
98
+ new_one.store
99
+ ```
100
+
101
+ ## Bucket Types
102
+
103
+ Riak 2 uses [bucket types][1] to enable groups of similar buckets to share
104
+ properties, configuration, and to namespace values within those buckets. Bucket
105
+ type support is integral to how CRDTs work.
106
+
107
+ [1]: http://docs.basho.com/riak/latest/dev/advanced/bucket-types
108
+
109
+ In versions 2.2.0 and newer of this client, bucket types have a first-class
110
+ representation, and can be used to create `BucketTyped::Bucket` objects that are
111
+ namespaced differently from regular `Riak::Bucket` objects.
112
+
113
+ ```ruby
114
+ # This example assumes you have a "beverages" bucket type.
115
+ beverages = client.bucket_type 'beverages'
116
+
117
+ coffees = beverages.bucket 'coffees'
118
+ untyped_coffees = client.bucket 'coffees'
119
+
120
+ chapadao = coffees.new 'chapadao'
121
+ chapadao.data = "Chapadao de Ferro"
122
+ chapadao.store # stores this in the "beverages" bucket type
123
+
124
+ untyped_coffees.get 'chapadao' # raises error, not found
125
+ coffees.get 'chapadao' # succeeds
126
+
127
+ chapadao.reload # succeeds
128
+
129
+ untyped_coffees.delete 'chapadao' # silently fails to delete it
130
+ chapadao.delete # deletes it
131
+ coffees.delete 'chapadao' # deletes it
132
+ ```
133
+
134
+ Client 2.0 and 2.1 code that uses the `type` argument to methods still works:
135
+
136
+ ```ruby
137
+ coffees = client.bucket 'coffees'
138
+
139
+ chapadao = coffees.new 'chapadao'
140
+ chapadao.data = "Chapadao de Ferro"
141
+ chapadao.store type: 'beverages' # stores this in the "beverages" bucket type
142
+
143
+ coffees.get 'chapadao' # raises error, not found
144
+ coffees.get 'chapadao', type: 'beverages' # succeeds
145
+
146
+ chapadao.reload # raises error, not found
147
+ chapadao.reload type: 'beverages' # succeeds
148
+
149
+ chapadao.delete # silently fails to delete it
150
+ coffees.delete 'chapadao' # silently fails to delete it
151
+
152
+ chapadao.delete type: 'beverages' # deletes it
153
+ coffees.delete 'chapadao', type: 'beverages' # deletes it
154
+ ```
155
+
156
+ ## Map-Reduce Example
157
+
158
+ ``` ruby
159
+ # Assuming you've already instantiated a client, get the album titles for The Beatles
160
+ results = Riak::MapReduce.new(client).
161
+ add("artists","Beatles").
162
+ link(:bucket => "albums").
163
+ map("function(v){ return [JSON.parse(v.values[0].data).title]; }", :keep => true).run
164
+
165
+ p results # => ["Please Please Me", "With The Beatles", "A Hard Day's Night",
166
+ # "Beatles For Sale", "Help!", "Rubber Soul",
167
+ # "Revolver", "Sgt. Pepper's Lonely Hearts Club Band", "Magical Mystery Tour",
168
+ # "The Beatles", "Yellow Submarine", "Abbey Road", "Let It Be"]
169
+ ```
170
+
171
+ ## Riak Search Examples
172
+
173
+ This client supports the new Riak Search 2 (codenamed "Yokozuna"). For more information about Riak Search, see [the Riak documentation](http://docs.basho.com/riak/latest/dev/using/search/).
174
+
175
+ This documentation assumes there's a `yokozuna` bucket type created and activated.
176
+
177
+ ``` ruby
178
+ # Create a client and bucket.
179
+ client = Riak::Client.new
180
+ bucket_type = client.bucket_type 'yokozuna'
181
+ bucket = bucket_type.bucket 'pizzas'
182
+
183
+ # Create an index and add it to a typed bucket. Setting the index on the bucket
184
+ # may fail until the index creation has propagated.
185
+ index = Riak::Search::Index.new 'pizzas'
186
+ index.exist? #=> false
187
+ index.create!
188
+ client.set_bucket_props bucket, {search_index: 'pizzas'}, 'yokozuna'
189
+
190
+ # Store some records for indexing
191
+ meat = bucket.new 'meat'
192
+ meat.data = {toppings_ss: %w{pepperoni ham sausage}}
193
+ meat.store type: 'yokozuna'
194
+
195
+ hawaiian = bucket.new 'hawaiian'
196
+ hawaiian.data = {toppings_ss: %w{ham pineapple}}
197
+ hawaiian.store type: 'yokozuna'
198
+
199
+ # Search the pizzas index for hashes that have a "ham" entry in the toppings_ss array
200
+ query = Riak::Search::Query.new client, index, 'toppings_ss:ham'
201
+ query.rows = 5 # return the first five pizzas
202
+
203
+ result = query.results # returns a ResultsCollection object
204
+ result.length # number of results returned
205
+ result.num_found # total number of results found, including ones not returned
206
+
207
+ pizza_result = result.first # a ResultDocument of the first pizza
208
+ pizza_result.score # score of the match
209
+ pizza_result.key # also pizza.bucket and pizza.bucket_type
210
+
211
+ pizza = pizza_result.robject # load the actual RObject for the match
212
+ ```
213
+
214
+ ## Secondary Index Examples
215
+
216
+ Riak supports secondary indexes. Secondary indexing, or "2i," gives you the
217
+ ability to tag objects with multiple queryable values at write time, and then
218
+ query them later.
219
+
220
+ * [Using Secondary Indexes](http://docs.basho.com/riak/latest/dev/using/2i/)
221
+ * [Secondary Index implementation notes](http://docs.basho.com/riak/latest/dev/advanced/2i/)
222
+
223
+ ### Tagging Objects
224
+
225
+ Objects are tagged with a hash kept behind the `indexes` method. Secondary index
226
+ storage logic is in `lib/riak/rcontent.rb`.
227
+
228
+ ```ruby
229
+ object = bucket.get_or_new 'cobb.salad'
230
+
231
+ # Indexes end with the "_bin" suffix to indicate they're binary or string
232
+ # indexes. They can have multiple values.
233
+ object.indexes['ingredients_bin'] = %w{lettuce tomato bacon egg chives}
234
+
235
+ # Indexes ending with the "_int" suffix are indexed as integers. They can
236
+ # have multiple values too.
237
+ object.indexes['calories_int'] = [220]
238
+
239
+ # You must re-save the object to store indexes.
240
+ object.store
241
+ ```
242
+
243
+ ### Finding Objects
244
+
245
+ Secondary index queries return a list of keys exactly matching a scalar or
246
+ within a range.
247
+
248
+ ```ruby
249
+ # The Bucket#get_index method allows querying by scalar...
250
+ bucket.get_index 'calories_int', 220 # => ['cobb.salad']
251
+
252
+ # or range.
253
+ bucket.get_index 'calories_int', 100..300 # => ['cobb.salad']
254
+
255
+ # Binary indexes also support both ranges and scalars.
256
+ bucket.get_index 'ingredients_bin', 'tomata'..'tomatz' # => ['cobb.salad']
257
+
258
+ # The collection from #get_index also provides a continuation for pagination:
259
+ c = bucket.get_index 'ingredients_bin', 'lettuce', max_results: 5
260
+ c.length # => 5
261
+ c.continuation # => "g2gCbQAAA="
262
+
263
+ # You can use that continuation to get the next page of results:
264
+ c2 = bucket.get_index 'ingredients_bin', 'lettuce', max_results: 5, continuation: c.continuation
265
+
266
+ # More complicated operations may benefit by using the `SecondaryIndex` object:
267
+ q = Riak::SecondaryIndex.new bucket, 'ingredients_bin', 'lettuce', max_results: 5
268
+
269
+ # SecondaryIndex objects give you access to the keys...
270
+ q.keys # => ['cobb.salad', 'wedge.salad', 'buffalo_chicken.wrap', ...]
271
+
272
+ # but can also fetch values for you in parallel.
273
+ q.values # => [<RObject {recipes,cobb.salad} ...>, <RObject {recipes,wedge...
274
+
275
+ # They also provide simpler pagination:
276
+ q.has_next_page? # => true
277
+ q2 = q.next_page
278
+ ```
279
+
280
+ ## Riak 2 Data Types
281
+
282
+ Riak 2 features new distributed data structures: counters, sets, and maps
283
+ (containing counters, flags, maps, registers, and sets). These are implemented
284
+ by the Riak database as Convergent Replicated Data Types.
285
+
286
+ Riak data type support requires bucket types to be configured to support each
287
+ top-level data type. If you're just playing around, use the
288
+ [Riak Ruby Vagrant](https://github.com/basho-labs/riak-ruby-vagrant) setup to
289
+ get started with the appropriate configuration and bucket types quickly.
290
+
291
+ The examples below presume that the appropriate bucket types are named
292
+ `counters`, `maps`, and `sets`; these bucket type names are the client's defaults.
293
+ Viewing and changing the defaults is easy:
294
+
295
+ ```ruby
296
+ Riak::Crdt::DEFAULT_BUCKET_TYPES[:set] #=> "sets"
297
+
298
+ Riak::Crdt::DEFAULT_BUCKET_TYPES[:set] = "a_cooler_set"
299
+ ```
300
+
301
+ The top-level CRDT types have both immediate and batch mode. If you're doing
302
+ multiple writes to a single top-level counter or set, or updating multiple map
303
+ entries, batch mode will make fewer round-trips to Riak.
304
+
305
+ Top-level CRDT types accept `nil` as a key. This allows Riak to assign a random
306
+ key for them.
307
+
308
+ Deleting CRDTs requires you to use the key-value API for the time being.
309
+
310
+ ```ruby
311
+ brews = Riak::Crdt::Set.new bucket, 'brews'
312
+ brews.add 'espresso'
313
+ brews.add 'aeropress'
314
+
315
+ bucket.delete brews.key, type: brews.bucket_type
316
+ ```
317
+
318
+
319
+ ### Counters
320
+
321
+ Riak 2 integer counters have one operation: increment by an integer.
322
+
323
+ ```ruby
324
+ counter = Riak::Crdt::Counter.new bucket, key
325
+
326
+ counter.value #=> 15
327
+
328
+ counter.increment
329
+
330
+ counter.value #=> 16
331
+
332
+ counter.increment 3
333
+
334
+ counter.value #=> 19
335
+
336
+ counter.decrement
337
+
338
+ counter.value #=> 18
339
+ ```
340
+
341
+ Counter operations can be batched:
342
+
343
+ ```ruby
344
+ counter.batch do |c|
345
+ c.increment
346
+ c.increment 5
347
+ end
348
+ ```
349
+
350
+ ### Maps
351
+
352
+ Riak 2 maps can contain counters, flags (booleans), registers (strings), sets, and
353
+ other maps.
354
+
355
+ Maps are similar but distinct from the standard Ruby `Hash`. Entries are
356
+ segregated by both name and type, so you can have counters, registers, and sets inside a map that all have the same name.
357
+
358
+ ```ruby
359
+ map = Riak::Crdt::Map.new bucket, key
360
+
361
+ map.counters['potatoes'].value #=> 5
362
+ map.sets['potatoes'].include? 'yukon gold' #=> true
363
+
364
+ map.sets['cacti'].value #=> #<Set: {"saguaro", "prickly pear", "fishhook"}>
365
+ map.sets['cacti'].remove 'prickly pear'
366
+
367
+ map.registers['favorite butterfly'] = 'the mighty monarch'
368
+
369
+ map.flags['pet cat'] = true
370
+
371
+ map.maps['atlantis'].registers['location'] #=> 'kennedy space center'
372
+
373
+ map.counters.delete 'thermometers'
374
+ ```
375
+
376
+ Maps are a prime candidate for batched operations:
377
+
378
+ ```ruby
379
+ map.batch do |m|
380
+ m.counters['hits'].increment
381
+ m.sets['followers'].add 'basho_elevator'
382
+ end
383
+ ```
384
+
385
+ Frequently, you might want a map with a Riak-assigned name instead of one you
386
+ come up with yourself:
387
+
388
+ ```ruby
389
+ map = Riak::Crdt::Map.new bucket, nil
390
+
391
+ map.registers['coat_pattern'] = 'tabby'
392
+
393
+ map.key #=> "2do4NvcurWhXYNQg8HoIR9zedJV"
394
+ ```
395
+
396
+ ### Sets
397
+
398
+ Sets are an unordered collection of entries.
399
+
400
+ **PROTIP:** Ruby and Riak Ruby Client both have classes called `Set`. Be careful
401
+ to refer to the Ruby version as `::Set` and the Riak client version as
402
+ `Riak::Crdt::Set`.
403
+
404
+ ```ruby
405
+ set = Riak::Crdt::Set.new bucket, key
406
+
407
+ set.members #=> #<Set: {"Edinburgh", "Leeds", "London"}>
408
+
409
+ set.add "Newcastle"
410
+ set.remove "London"
411
+
412
+ set.include? "Leeds" #=> true
413
+ ```
414
+
415
+ Sets support batched operations:
416
+
417
+ ```ruby
418
+ set.batch do |s|
419
+ s.add "York"
420
+ s.add "Aberdeen"
421
+ s.remove "Newcastle"
422
+ end
423
+ ```
424
+
425
+ ### Client Implementation Notes
426
+
427
+ The client code for these types is in the `Riak::Crdt` namespace, and mostly
428
+ in the `lib/riak/crdt` directory.
429
+
430
+ ## Riak 1.4 Counters
431
+
432
+ For more information about 1.4-style counters in Riak, see [the Basho documentation](http://docs.basho.com/riak/latest/dev/references/http/counters/).
433
+
434
+ Counter records are automatically persisted on increment or decrement. The initial default value is 0.
435
+
436
+ ``` ruby
437
+ # Firstly, ensure that your bucket is allow_mult set to true
438
+ bucket = client.bucket "counters"
439
+ bucket.allow_mult = true
440
+
441
+ # You can create a counter by using the bucket's counter method
442
+ counter = bucket.counter("counter-key-here")
443
+ counter.increment
444
+ => nil
445
+
446
+ p counter.value
447
+ 1
448
+ => 1
449
+
450
+ # Let's increment one more time and then retrieve it from the database
451
+ counter.increment
452
+
453
+ # Retrieval is similar to creation
454
+ persisted_counter = Riak::Counter.new(bucket, "counter-key-here")
455
+
456
+ p persisted_counter.value
457
+ 2
458
+ => 2
459
+
460
+ # We can also increment by a specified number
461
+ persisted_counter.increment(20)
462
+ p persisted_counter.value
463
+ 22
464
+ => 22
465
+
466
+ # Decrement works much the same
467
+ persisted_counter.decrement
468
+ persisted_counter.value
469
+ => 21
470
+
471
+ persisted_counter.decrement(6)
472
+ persisted_counter.value
473
+ => 15
474
+
475
+ # Incrementing by anything other than integer will throw an ArgumentError
476
+ persisted_counter.increment "nonsense"
477
+ ArgumentError: Counters can only be incremented or decremented by integers.
478
+ ```
479
+
480
+ That's about it. PN Counters in Riak are distributed, so each node will receive the proper increment/decrement operation. Enjoy using them.
481
+
482
+ ## Instrumentation
483
+
484
+ The Riak client has built-in event hooks for all major over-the-wire operations including:
485
+
486
+ * riak.list_buckets
487
+ * riak.list_keys
488
+ * riak.set_bucket_props
489
+ * riak.get_bucket_props
490
+ * riak.clear_bucket_props
491
+ * riak.get_index
492
+ * riak.store_object
493
+ * riak.get_object
494
+ * riak.reload_object
495
+ * riak.delete_object
496
+ * riak.map_reduce
497
+ * riak.ping
498
+
499
+ Events are propogated using [ActiveSupport::Notifications](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html), provided by the [Instrumentable](https://github.com/siyegen/instrumentable) gem.
500
+
501
+ ### Enabling
502
+
503
+ Instrumentation is opt-in. If `instrumentable` is not available, instrumentation will not be available. To turn on instrumentation, simply require the `instrumentable` gem in your app's Gemfile:
504
+
505
+ ```ruby
506
+ gem 'instrumentable', '~> 1.1.0'
507
+ ```
508
+
509
+ Then, to subscribe to events:
510
+
511
+ ```ruby
512
+ ActiveSupport::Notifications.subscribe(/^riak\.*/) do |name, start, finish, id, payload|
513
+ name # => String, name of the event (such as 'riak.get_object' from above)
514
+ start # => Time, when the instrumented block started execution
515
+ finish # => Time, when the instrumented block ended execution
516
+ id # => String, unique ID for this notification
517
+ payload # => Hash, the payload
518
+ end
519
+ ```
520
+
521
+ The payload for each event contains the following keys:
522
+
523
+ * `:client_id`: The client_id of the Riak client
524
+ * `:_method_args`: The array of method arguments for the instrumented method. For instance, for `riak.get_object`, this value would resemble `[<Riak::Bucket ...>, 'key', {}]`
525
+
526
+ ## Running Specs
527
+
528
+ We aim to have a comprehensive and fast set of tests, implemented using a modern,
529
+ well-supported version of RSpec. These tests include both unit specs for
530
+ individual classes, and integration specs that ensure the client works properly
531
+ with an actual Riak instance.
532
+
533
+ The [Riak Ruby Vagrant][1] virtual machine's Riak configuration is normally
534
+ used to test this client in development. Once it's up and running, configure
535
+ the Ruby `test_client.yml` on the host machine to connect to `pb_port: 17017`
536
+ and test away.
537
+
538
+ [1]: https://github.com/basho-labs/riak-ruby-vagrant
539
+
540
+ Configuring the Riak node the tests connect to is done via the
541
+ `spec/support/test_client.yml` file, which is loaded into a Ruby hash with
542
+ symbolized keys, and passed to `Riak::Client.new`.
543
+
544
+ ```yml
545
+ # test_client.yml
546
+ pb_port: 10017
547
+ # UNCOMMENT AUTHENTICATION SECTION WHEN RIAK HAS SECURITY ENABLED
548
+ # authentication:
549
+ # user: user
550
+ # password: password
551
+ # ca_file: spec/support/certs/ca.crt
552
+ ```
553
+
554
+ ### Spec dependencies
555
+
556
+ Specs depend on the following Riak configurations:
557
+
558
+ * The **LevelDB backend** is necessary for testing secondary indexes.
559
+ * **allow_mult** is required for many features: conflict resolution, and legacy
560
+ counters among them.
561
+ * **Riak Search 2.0** ("Yokozuna") must be configured for testing full-text
562
+ search.
563
+
564
+ The following bucket types are used during testing:
565
+
566
+ ```shell
567
+ riak-admin bucket-type create counters '{"props":{"datatype":"counter", "allow_mult":true}}'
568
+ riak-admin bucket-type create other_counters '{"props":{"datatype":"counter", "allow_mult":true}}'
569
+ riak-admin bucket-type create maps '{"props":{"datatype":"map", "allow_mult":true}}'
570
+ riak-admin bucket-type create sets '{"props":{"datatype":"set", "allow_mult":true}}'
571
+ riak-admin bucket-type create yokozuna '{"props":{}}'
572
+
573
+ riak-admin bucket-type activate other_counters
574
+ riak-admin bucket-type activate counters
575
+ riak-admin bucket-type activate maps
576
+ riak-admin bucket-type activate sets
577
+ riak-admin bucket-type activate yokozuna
578
+ ```
579
+
580
+ Client tests run both with and without security enabled, as we have to test
581
+ several positive and negative paths. The tests broadly depend on these users
582
+ and roles:
583
+
584
+ ```shell
585
+ riak-admin security add-user user password=password
586
+ riak-admin security add-user certuser
587
+
588
+ riak-admin security add-source user 0.0.0.0/0 password
589
+ riak-admin security add-source certuser 0.0.0.0/0 certificate
590
+
591
+ riak-admin security grant riak_kv.get,riak_kv.put,riak_kv.delete,\
592
+ riak_kv.index,riak_kv.list_keys,riak_kv.list_buckets,\
593
+ riak_core.get_bucket,riak_core.set_bucket,\
594
+ riak_core.get_bucket_type,riak_core.set_bucket_type,\
595
+ search.admin,search.query,riak_kv.mapreduce on any to user
596
+ ```
597
+
598
+ ## How to Contribute
599
+
600
+ * Fork the project on [Github](http://github.com/basho/riak-ruby-client). If you have already forked, use `git pull --rebase` to reapply your changes on top of the mainline. Example:
601
+
602
+ ``` bash
603
+ $ git checkout master
604
+ $ git pull --rebase basho master
605
+ ```
606
+
607
+ * Copy spec/support/test_server.yml.example to spec/support/test_server.yml and change that file according to your local installation of riak.
608
+
609
+ * Create a topic branch. If you've already created a topic branch, rebase it on top of changes from the mainline "master" branch. Examples:
610
+ * New branch:
611
+
612
+ ``` bash
613
+ $ git checkout -b topic
614
+ ```
615
+ * Existing branch:
616
+
617
+ ``` bash
618
+ $ git rebase master
619
+ ```
620
+ * Write an RSpec example or set of examples that demonstrate the necessity and validity of your changes. **Patches without specs will most often be ignored. Just do it, you'll thank me later.** Documentation patches need no specs, of course.
621
+ * Make your feature addition or bug fix. Make your specs and stories pass (green).
622
+ * Run the suite using multiruby or rvm to ensure cross-version compatibility.
623
+ * Cleanup any trailing whitespace in your code (try @whitespace-mode@ in Emacs, or "Remove Trailing Spaces in Document" in the "Text" bundle in Textmate). You can use the `clean_whitespace` Rake task if you like.
624
+ * Commit, do not mess with Rakefile. If related to an existing issue in the [tracker](http://github.com/basho/ruby-riak-client/issues), include "Closes #X" in the commit message (where X is the issue number).
625
+ * Send a pull request to the Basho repository.
626
+
627
+ ## License & Copyright
628
+
629
+ Copyright &copy;2010-2015 Sean Cribbs and Basho Technologies, Inc.
630
+
631
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
632
+
633
+ [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
634
+
635
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
636
+
637
+ ## Auxillary Licenses
638
+
639
+ The included photo (spec/fixtures/cat.jpg) is Copyright &copy;2009 [Sean Cribbs](http://seancribbs.com/), and is licensed under the [Creative Commons Attribution Non-Commercial 3.0](http://creativecommons.org/licenses/by-nc/3.0) license.
640
+ !["Creative Commons"](http://i.creativecommons.org/l/by-nc/3.0/88x31.png)