class Connection
Nested
Definitions
attr :count
def write_request(arguments)
The redis server doesn't want actual objects (e.g. integers) but only bulk strings. So, we inline it for performance.
Implementation
def write_request(arguments)
write_lines("*#{arguments.size}")
@count += 1
arguments.each do |argument|
string = argument.to_s
write_lines("$#{string.bytesize}", string)
end
end
def write_lines(*arguments)
In the case of Redis, we do not want to perform a flush in every line, because each Redis command contains several lines. Flushing once per command is more efficient because it avoids unnecessary writes to the socket.
Implementation
def write_lines(*arguments)
if arguments.empty?
@stream.write(CRLF)
else
arguments.each do |arg|
@stream.write(arg)
@stream.write(CRLF)
end
end
end