Class: Riak::Client::ProtobuffsBackend

Inherits:
Object
  • Object
show all
Includes:
FeatureDetection, Util::Escape, Util::Translation
Defined in:
lib/riak/client/protobuffs_backend.rb

Direct Known Subclasses

BeefcakeProtobuffsBackend

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

FeatureDetection::VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#i18n_scope, #t

Constructor Details

#initialize(client, node) ⇒ ProtobuffsBackend



35
36
37
38
# File 'lib/riak/client/protobuffs_backend.rb', line 35

def initialize(client, node)
  @client = client
  @node = node
end

Instance Attribute Details

#clientObject

Returns the value of attribute client



33
34
35
# File 'lib/riak/client/protobuffs_backend.rb', line 33

def client
  @client
end

#nodeObject

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.



46
47
48
49
50
51
52
# 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 = {}) ⇒ 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.



62
63
64
65
66
67
68
69
70
71
72
73
# 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

#socketObject



80
81
82
# File 'lib/riak/client/protobuffs_backend.rb', line 80

def socket
  @socket ||= new_socket
end

#teardownObject

Gracefully shuts down this connection.



76
77
78
# File 'lib/riak/client/protobuffs_backend.rb', line 76

def teardown
  reset_socket
end