Class: Aerospike::TouchCommand

Inherits:
SingleCommand show all
Defined in:
lib/aerospike/command/touch_command.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Command

#execute, #set_delete, #set_exists, #set_operate, #set_query, #set_read, #set_read_for_key_only, #set_read_header, #set_scan, #set_touch, #set_udf, #set_write, #write_bins

Constructor Details

#initialize(cluster, policy, key) ⇒ TouchCommand

Returns a new instance of TouchCommand.



25
26
27
28
29
30
31
# File 'lib/aerospike/command/touch_command.rb', line 25

def initialize(cluster, policy, key)
  super(cluster, key)

  @policy = policy

  self
end

Instance Method Details

#get_nodeObject



33
34
35
# File 'lib/aerospike/command/touch_command.rb', line 33

def get_node
  @cluster.master_node(@partition)
end

#parse_resultObject



41
42
43
44
45
46
47
48
49
50
51
52
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
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/aerospike/command/touch_command.rb', line 41

def parse_result
  # Read header.
  begin
    @conn.read(@data_buffer, 8)
  rescue => e
    Aerospike.logger.error("parse result error: #{e}")
    raise e
  end

  # inflate if compressed
  compressed_sz = compressed_size
  if compressed_sz
    begin
      #waste 8 size bytes
      @conn.read(@data_buffer, 8)

      # read compressed message
      @conn.read(@data_buffer, sz - 8)

      # inflate the results
      # TODO: reuse the current buffer
      uncompressed = Zlib.inflate(@data_buffer.buf)

      @data_buffer = Buffer.new(-1, uncompressed)
    rescue => e
      Aerospike.logger.error("parse result error: #{e}")
      raise e
    end
  else
    begin
      bytes_read = @conn.read(@data_buffer, MSG_TOTAL_HEADER_SIZE - 8, 8)
    rescue => e
      Aerospike.logger.error("parse result error: #{e}")
      raise e
    end
  end

  result_code = @data_buffer.read(13).ord & 0xFF

  return if result_code == 0

  if result_code == Aerospike::ResultCode::FILTERED_OUT
    if @policy.fail_on_filtered_out
      raise Aerospike::Exceptions::Aerospike.new(result_code, nil, [@node])
    end
    return
  end

  raise Aerospike::Exceptions::Aerospike.new(result_code, nil, [@node])
end

#write_bufferObject



37
38
39
# File 'lib/aerospike/command/touch_command.rb', line 37

def write_buffer
  set_touch(@policy, @key)
end