Class: Aerospike::BatchWrite
- Inherits:
-
BatchRecord
- Object
- BatchRecord
- Aerospike::BatchWrite
- Defined in:
- lib/aerospike/batch_write.rb
Overview
Batch key and read/write operations with write policy.
Constant Summary collapse
- DEFAULT_BATCH_WRITE_POLICY =
BatchWritePolicy.new
Instance Attribute Summary collapse
-
#ops ⇒ Object
Required operations for this key.
-
#policy ⇒ Object
Optional write policy.
Attributes inherited from BatchRecord
#has_write, #in_doubt, #key, #record, #result_code
Instance Method Summary collapse
-
#==(other) ⇒ Object
Optimized reference equality check to determine batch wire protocol repeat flag.
-
#initialize(key, ops, opt = {}) ⇒ BatchWrite
constructor
Initialize batch key and read/write operations.
-
#size ⇒ Object
Return wire protocol size.
Methods inherited from BatchRecord
create_policy, #prepare, #set_error
Constructor Details
#initialize(key, ops, opt = {}) ⇒ BatchWrite
Initialize batch key and read/write operations.
Operation#get() is not allowed because it returns a variable number of bins and makes it difficult (sometimes impossible) to lineup operations with results. Instead, use Operation#get(bin_name) for each bin name.
37 38 39 40 41 |
# File 'lib/aerospike/batch_write.rb', line 37 def initialize(key, ops, opt = {}) super(key, has_write: true) @policy = BatchRecord.create_policy(opt, BatchWritePolicy, DEFAULT_BATCH_WRITE_POLICY) @ops = ops end |
Instance Attribute Details
#ops ⇒ Object
Required operations for this key.
30 31 32 |
# File 'lib/aerospike/batch_write.rb', line 30 def ops @ops end |
#policy ⇒ Object
Optional write policy.
27 28 29 |
# File 'lib/aerospike/batch_write.rb', line 27 def policy @policy end |
Instance Method Details
#==(other) ⇒ Object
Optimized reference equality check to determine batch wire protocol repeat flag. For internal use only.
45 46 47 48 |
# File 'lib/aerospike/batch_write.rb', line 45 def ==(other) # :nodoc: other && other.instance_of?(self.class) && @ops == other.ops && @policy == other.policy && (@policy.nil? || !@policy.send_key) end |
#size ⇒ Object
Return wire protocol size. For internal use only.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/aerospike/batch_write.rb', line 53 def size # :nodoc: size = 6 # gen(2) + exp(4) = 6 size += @policy&.filter_exp&.size if @policy&.filter_exp if @policy&.send_key size += @key.user_key.estimate_size + Aerospike::FIELD_HEADER_SIZE + 1 end has_write = false @ops&.each do |op| if op.is_write? has_write = true end size += op.bin_name.bytesize + Aerospike::OPERATION_HEADER_SIZE if op.bin_name size += op.bin_value.estimate_size if op.bin_value end unless has_write raise AerospikeException.new(ResultCode::PARAMETER_ERROR, "Batch write operations do not contain a write") end size end |