Sha256: cd62369a5a244178dff1234963e730c25fd99b517b7b75ec1c1be736843f9ddf

Contents?: true

Size: 893 Bytes

Versions: 8

Compression:

Stored size: 893 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
              j = j.encoding == Encoding::BINARY ? j : j.b
              command << "$#{j.bytesize}"
              command << j
            end
          else
            i = i.to_s
            i = i.encoding == Encoding::BINARY ? i : i.b
            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

8 entries across 8 versions & 2 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/redis-4.8.1/lib/redis/connection/command_helper.rb
redis-4.8.1 lib/redis/connection/command_helper.rb
redis-4.8.0 lib/redis/connection/command_helper.rb
redis-4.7.1 lib/redis/connection/command_helper.rb
redis-4.7.0 lib/redis/connection/command_helper.rb
redis-4.6.0 lib/redis/connection/command_helper.rb
redis-4.5.1 lib/redis/connection/command_helper.rb
redis-4.5.0 lib/redis/connection/command_helper.rb