Class: RedisProtocol::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/redis-protocol/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Response

Returns a new instance of Response.



17
18
19
20
21
# File 'lib/redis-protocol/response.rb', line 17

def initialize(data)
  @raw_data = data
  @raw_data += RedisProtocol::UnifiedProtocol::DELIMITER unless @raw_data.end_with? RedisProtocol::UnifiedProtocol::DELIMITER
  @result = RedisProtocol::UnifiedProtocol.parse @raw_data
end

Instance Attribute Details

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



4
5
6
# File 'lib/redis-protocol/response.rb', line 4

def raw_data
  @raw_data
end

#resultObject (readonly)

Returns the value of attribute result.



4
5
6
# File 'lib/redis-protocol/response.rb', line 4

def result
  @result
end

Instance Method Details

#<<(value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/redis-protocol/response.rb', line 6

def <<(value)
  @result += value.result
  unless value.result.empty?
    start = @raw_data.index('*') + 1
    finish = @raw_data.index(RedisProtocol::UnifiedProtocol::DELIMITER)
    @raw_data[start...finish] = @result.length.to_s

    @raw_data += value.raw_data[(value.raw_data.index(RedisProtocol::UnifiedProtocol::DELIMITER) + RedisProtocol::UnifiedProtocol::DELIMITER.length)..-1]
  end
end