Class: Riak::Client::ProtobuffsBackend
- Includes:
- FeatureDetection, Util::Escape, Util::Translation
- Defined in:
- lib/riak/client/protobuffs_backend.rb
Direct Known Subclasses
Constant Summary collapse
- MESSAGE_CODES =
BeefcakeMessageCodes
- UINTMAX =
0xffffffff
- QUORUMS =
{ "one" => UINTMAX - 1, "quorum" => UINTMAX - 2, "all" => UINTMAX - 3, "default" => UINTMAX - 4 }.freeze
Constants included from FeatureDetection
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#node ⇒ Object
Returns the value of attribute node.
Class Method Summary collapse
Instance Method Summary collapse
-
#get_index(bucket, index, query) ⇒ Array<String>
Performs a secondary-index query via emulation through MapReduce.
-
#initialize(client, node) ⇒ ProtobuffsBackend
constructor
A new instance of ProtobuffsBackend.
-
#search(index, query, options = {}) ⇒ Hash
Performs search query via emulation through MapReduce.
- #socket ⇒ Object
-
#teardown ⇒ Object
Gracefully shuts down this connection.
Methods included from FeatureDetection
#http_props_clearable?, #index_pagination?, #index_return_terms?, #index_streaming?, #key_object_bucket_timeouts?, #mapred_phaseless?, #pb_conditionals?, #pb_head?, #pb_indexes?, #pb_search?, #quorum_controls?, #server_version, #tombstone_vclocks?
Methods included from Util::Escape
#escape, #maybe_escape, #maybe_unescape, #unescape
Methods included from Util::Translation
Constructor Details
#initialize(client, node) ⇒ ProtobuffsBackend
Returns a new instance of ProtobuffsBackend.
36 37 38 39 |
# File 'lib/riak/client/protobuffs_backend.rb', line 36 def initialize(client, node) @client = client @node = node end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
33 34 35 |
# File 'lib/riak/client/protobuffs_backend.rb', line 33 def client @client end |
#node ⇒ Object
Returns the value of attribute node.
34 35 36 |
# File 'lib/riak/client/protobuffs_backend.rb', line 34 def node @node end |
Class Method Details
.simple(method, code) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/riak/client/protobuffs_backend.rb', line 26 def self.simple(method, code) define_method method do socket.write([1, MESSAGE_CODES.index(code)].pack('NC')) decode_response end end |
Instance Method Details
#get_index(bucket, index, query) ⇒ Array<String>
Performs a secondary-index query via emulation through MapReduce.
47 48 49 50 51 52 53 |
# File 'lib/riak/client/protobuffs_backend.rb', line 47 def get_index(bucket, index, query) mr = Riak::MapReduce.new(client).index(bucket, index, query) unless mapred_phaseless? mr.reduce(%w[riak_kv_mapreduce reduce_identity], :arg => {:reduce_phase_only_1 => true}, :keep => true) end mapred(mr).map {|p| p.last } end |
#search(index, query, options = {}) ⇒ Hash
Performs search query via emulation through MapReduce. This has more limited capabilites than native queries. Essentially, only the ‘id’ field of matched documents will ever be returned, the ‘fl’ and other options have no effect.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/riak/client/protobuffs_backend.rb', line 63 def search(index, query, = {}) mr = Riak::MapReduce.new(client).search(index || 'search', query) unless mapred_phaseless? mr.reduce(%w[riak_kv_mapreduce reduce_identity], :arg => {:reduce_phase_only_1 => true}, :keep => true) end docs = mapred(mr).map {|d| {'id' => d[1] } } # Since we don't get this information back from the MapReduce, # we have to fake the max_score and num_found. { 'docs' => docs, 'num_found' => docs.size, 'max_score' => 0.0 } end |
#socket ⇒ Object
81 82 83 |
# File 'lib/riak/client/protobuffs_backend.rb', line 81 def socket @socket ||= new_socket end |
#teardown ⇒ Object
Gracefully shuts down this connection.
77 78 79 |
# File 'lib/riak/client/protobuffs_backend.rb', line 77 def teardown reset_socket end |