PageRenderTime 19ms CodeModel.GetById 11ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/redis-3.0.7/lib/redis/connection/command_helper.rb

https://github.com/delowong/logstash
Ruby | 44 lines | 36 code | 7 blank | 1 comment | 2 complexity | 914733ca08dd002f52c80d0faf309ddd MD5 | raw file
 1class Redis
 2  module Connection
 3    module CommandHelper
 4
 5      COMMAND_DELIMITER = "\r\n"
 6
 7      def build_command(args)
 8        command = [nil]
 9
10        args.each do |i|
11          if i.is_a? Array
12            i.each do |j|
13              j = j.to_s
14              command << "$#{j.bytesize}"
15              command << j
16            end
17          else
18            i = i.to_s
19            command << "$#{i.bytesize}"
20            command << i
21          end
22        end
23
24        command[0] = "*#{(command.length - 1) / 2}"
25
26        # Trailing delimiter
27        command << ""
28        command.join(COMMAND_DELIMITER)
29      end
30
31    protected
32
33      if defined?(Encoding::default_external)
34        def encode(string)
35          string.force_encoding(Encoding::default_external)
36        end
37      else
38        def encode(string)
39          string
40        end
41      end
42    end
43  end
44end