class Riak::Client::ProtobuffsBackend
Constants
- MESSAGE_CODES
- QUORUMS
- UINTMAX
Attributes
client[RW]
node[RW]
Public Class Methods
new(client, node)
click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 35 def initialize(client, node) @client = client @node = node end
simple(method, code)
click to toggle source
# 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
Public Instance Methods
get_index(bucket, index, query)
click to toggle source
Performs a secondary-index query via emulation through MapReduce
. @param [String, Bucket] bucket the bucket to query @param [String] index the index to query @param [String, Integer, Range] query the equality query or
range query to perform
@return [Array<String>] a list of keys matching the query
# File lib/riak/client/protobuffs_backend.rb, line 46 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 = {})
click to toggle source
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. @param [String] index the index to query @param [String] query the Lucene-style search query @param [Hash] options ignored in MapReduce
emulation @return [Hash] the search results
# File lib/riak/client/protobuffs_backend.rb, line 62 def search(index, query, options = {}) 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()
click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 80 def socket @socket ||= new_socket end
teardown()
click to toggle source
Gracefully shuts down this connection.
# File lib/riak/client/protobuffs_backend.rb, line 76 def teardown reset_socket end
Private Instance Methods
decode_response()
click to toggle source
Implemented by subclasses
# File lib/riak/client/protobuffs_backend.rb, line 90 def decode_response raise NotImplementedError end
denormalize_quorum_value(q)
click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 138 def denormalize_quorum_value(q) QUORUMS.invert[q] || q.to_i end
get_server_version()
click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 85 def get_server_version server_info[:server_version] end
new_socket()
click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 94 def new_socket raise NotImplementedError end
normalize_quorum_value(q)
click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 134 def normalize_quorum_value(q) QUORUMS[q.to_s] || q.to_i end
normalize_quorums(options = {})
click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 124 def normalize_quorums(options = {}) options.dup.tap do |o| [:r, :pr, :w, :pw, :dw, :rw].each do |k| next o[k] = normalize_quorum_value(o[k]) if o[k] s = k.to_s o[k] = o[s] = denormalize_quorum_value(o[s]) if o[s] end end end
prune_unsupported_options(req, options = {})
click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 104 def prune_unsupported_options(req, options = {}) unless quorum_controls? [:notfound_ok, :basic_quorum, :pr, :pw].each {|k| options.delete k } end unless key_object_bucket_timeouts? options.delete :timeout end unless pb_head? [:head, :return_head].each {|k| options.delete k } end unless tombstone_vclocks? options.delete :deletedvclock options.delete :vclock if req == :DelReq end unless pb_conditionals? [:if_not_modified, :if_none_match, :if_modified].each {|k| options.delete k } end options end
reset_socket()
click to toggle source
# File lib/riak/client/protobuffs_backend.rb, line 98 def reset_socket reset_server_version @socket.close if @socket && !@socket.closed? @socket = nil end