lib/aerospike/command/read_command.rb in aerospike-2.1.1 vs lib/aerospike/command/read_command.rb in aerospike-2.2.0

- old
+ new

@@ -15,20 +15,21 @@ # the License. require 'aerospike/record' require 'aerospike/command/single_command' +require 'aerospike/policy/operate_policy' require 'aerospike/utils/epoc' require 'aerospike/value/value' module Aerospike private class ReadCommand < SingleCommand #:nodoc: - attr_reader :record + attr_reader :record, :policy def initialize(cluster, policy, key, bin_names) super(cluster, key) @bin_names = bin_names @@ -106,10 +107,11 @@ end def parse_record(op_count, field_count, generation, expiration) bins = op_count > 0 ? {} : nil receive_offset = 0 + single_bin_value = (!(OperatePolicy === policy) || policy.record_bin_multiplicity == RecordBinMultiplicity::SINGLE) # There can be fields in the response (setname etc). # But for now, ignore them. Expose them to the API if needed in the future. if field_count > 0 # Just skip over all the fields @@ -127,21 +129,28 @@ particle_type = @data_buffer.read(receive_offset+5).ord name_size = @data_buffer.read(receive_offset+7).ord name = @data_buffer.read(receive_offset+8, name_size).force_encoding('utf-8') receive_offset += 4 + 4 + name_size - particle_bytes_size = op_size - (4 + name_size) value = Aerospike.bytes_to_particle(particle_type, @data_buffer, receive_offset, particle_bytes_size) receive_offset += particle_bytes_size - bins[name] = value + if single_bin_value || !bins.has_key?(name) + bins[name] = value + elsif (prev = bins[name]).kind_of?(OpResults) + prev << value + else + bins[name] = OpResults.new << prev << value + end i = i.succ end Record.new(@node, @key, bins, generation, expiration) end end # class + + class OpResults < Array; end end # module