/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

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