Module: Redis2::Connection::CommandHelper

Included in:
Ruby, Synchrony
Defined in:
lib/redis2/connection/command_helper.rb

Constant Summary collapse

COMMAND_DELIMITER =
"\r\n"

Instance Method Summary collapse

Instance Method Details

#build_command(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/redis2/connection/command_helper.rb', line 7

def build_command(args)
  command = [nil]

  args.each do |i|
    if i.is_a? Array
      i.each do |j|
        j = j.to_s
        command << "$#{j.bytesize}"
        command << j
      end
    else
      i = i.to_s
      command << "$#{i.bytesize}"
      command << i
    end
  end

  command[0] = "*#{(command.length - 1) / 2}"

  # Trailing delimiter
  command << ""
  command.join(COMMAND_DELIMITER)
end