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 =
Message Codes Enum
%W[ ErrorResp PingReq PingResp GetClientIdReq GetClientIdResp SetClientIdReq SetClientIdResp GetServerInfoReq GetServerInfoResp GetReq GetResp PutReq PutResp DelReq DelResp ListBucketsReq ListBucketsResp ListKeysReq ListKeysResp GetBucketReq GetBucketResp SetBucketReq SetBucketResp MapRedReq MapRedResp IndexReq IndexResp SearchQueryReq SearchQueryResp ].map {|s| s.intern }.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.
-
#teardown ⇒ Object
Gracefully shuts down this connection.
Methods included from FeatureDetection
#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.
57 58 59 60 |
# File 'lib/riak/client/protobuffs_backend.rb', line 57 def initialize(client, node) @client = client @node = node end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
55 56 57 |
# File 'lib/riak/client/protobuffs_backend.rb', line 55 def client @client end |
#node ⇒ Object
Returns the value of attribute node.
56 57 58 |
# File 'lib/riak/client/protobuffs_backend.rb', line 56 def node @node end |
Class Method Details
.simple(method, code) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/riak/client/protobuffs_backend.rb', line 48 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.
73 74 75 76 77 78 79 |
# File 'lib/riak/client/protobuffs_backend.rb', line 73 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.
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/riak/client/protobuffs_backend.rb', line 89 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 |
#teardown ⇒ Object
Gracefully shuts down this connection.
103 104 105 |
# File 'lib/riak/client/protobuffs_backend.rb', line 103 def teardown reset_socket end |