Class: Dalli::Protocol::Binary::ResponseHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/dalli/protocol/binary/response_header.rb

Overview

Class that encapsulates data parsed from a memcached response header.

Constant Summary collapse

SIZE =
24
FMT =
'@2nCCnNNQ'
NOT_STORED_STATUSES =
[2, 5].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buf) ⇒ ResponseHeader

Returns a new instance of ResponseHeader.

Raises:

  • (ArgumentError)


15
16
17
18
19
# File 'lib/dalli/protocol/binary/response_header.rb', line 15

def initialize(buf)
  raise ArgumentError, "Response buffer must be at least #{SIZE} bytes" unless buf.bytesize >= SIZE

  @key_len, @extra_len, @data_type, @status, @body_len, @opaque, @cas = buf.unpack(FMT)
end

Instance Attribute Details

#body_lenObject (readonly)

Returns the value of attribute body_len.



13
14
15
# File 'lib/dalli/protocol/binary/response_header.rb', line 13

def body_len
  @body_len
end

#casObject (readonly)

Returns the value of attribute cas.



13
14
15
# File 'lib/dalli/protocol/binary/response_header.rb', line 13

def cas
  @cas
end

#data_typeObject (readonly)

Returns the value of attribute data_type.



13
14
15
# File 'lib/dalli/protocol/binary/response_header.rb', line 13

def data_type
  @data_type
end

#extra_lenObject (readonly)

Returns the value of attribute extra_len.



13
14
15
# File 'lib/dalli/protocol/binary/response_header.rb', line 13

def extra_len
  @extra_len
end

#key_lenObject (readonly)

Returns the value of attribute key_len.



13
14
15
# File 'lib/dalli/protocol/binary/response_header.rb', line 13

def key_len
  @key_len
end

#opaqueObject (readonly)

Returns the value of attribute opaque.



13
14
15
# File 'lib/dalli/protocol/binary/response_header.rb', line 13

def opaque
  @opaque
end

#statusObject (readonly)

Returns the value of attribute status.



13
14
15
# File 'lib/dalli/protocol/binary/response_header.rb', line 13

def status
  @status
end

Instance Method Details

#not_found?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/dalli/protocol/binary/response_header.rb', line 25

def not_found?
  status == 1
end

#not_stored?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/dalli/protocol/binary/response_header.rb', line 30

def not_stored?
  NOT_STORED_STATUSES.include?(status)
end

#ok?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/dalli/protocol/binary/response_header.rb', line 21

def ok?
  status.zero?
end