Sha256: a91a71ef553be8bf57605bba5533cd44a75907509d253ac30c22ddca73bdbc9b

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

require 'redis/connection/registry'
require 'redis/errors'
require 'oxblood'

class Redis
  module Connection
    class Oxblood
      def self.connect(config)
        conn_type = config[:scheme] == 'unix' ? :unix : :tcp
        connection = ::Oxblood::Connection.public_send(:"connect_#{conn_type}", config)

        new(connection)
      end

      def initialize(connection)
        @connection = connection
      end

      def connected?
        @connection && @connection.connected?
      end

      def timeout=(timeout)
        @connection.timeout = timeout > 0 ? timeout : nil
      end

      def disconnect
        @connection.close
      end

      def write(command)
        @connection.send_command(command)
      end

      def read
        reply = @connection.read_response
        reply = encode(reply) if reply.is_a?(String)
        reply = CommandError.new(reply.message) if reply.is_a?(::Oxblood::Protocol::RError)
        reply
      rescue ::Oxblood::Protocol::ParserError => e
        raise Redis::ProtocolError.new(e.message)
      end

      if defined?(Encoding::default_external)
        def encode(string)
          string.force_encoding(Encoding::default_external)
        end
      else
        def encode(string)
          string
        end
      end
    end
  end
end

Redis::Connection.drivers << Redis::Connection::Oxblood

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oxblood-0.1.0.dev3 lib/redis/connection/oxblood.rb
oxblood-0.1.0.dev2 lib/redis/connection/oxblood.rb
oxblood-0.1.0.dev1 lib/redis/connection/oxblood.rb