Sha256: e23fdc123f70f78e85be96f293b0c1634e96a508f8c8e2834fdd248ceb59e3aa

Contents?: true

Size: 777 Bytes

Versions: 9

Compression:

Stored size: 777 Bytes

Contents

# frozen_string_literal: true

class Redis
  module Connection
    module CommandHelper
      COMMAND_DELIMITER = "\r\n"

      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

      protected

      def encode(string)
        string.force_encoding(Encoding.default_external)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
redis-4.4.0 lib/redis/connection/command_helper.rb
redis-4.3.1 lib/redis/connection/command_helper.rb
redis-4.3.0 lib/redis/connection/command_helper.rb
redis-4.2.5 lib/redis/connection/command_helper.rb
redis-4.2.4 lib/redis/connection/command_helper.rb
redis-4.2.3 lib/redis/connection/command_helper.rb
redis-4.2.2 lib/redis/connection/command_helper.rb
redis-4.2.1 lib/redis/connection/command_helper.rb
redis-4.2.0 lib/redis/connection/command_helper.rb