Sha256: 89539ff9ec542607f4b09f6c8e438b55cfa2d967dbc5eb6d0ee887093452a5a6

Contents?: true

Size: 1.46 KB

Versions: 9

Compression:

Stored size: 1.46 KB

Contents

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

class Redis
  module Connection
    class Oxblood
      def self.connect(config)
        unless config[:path]
          config = config.dup
          config.delete(:path)
        end
        connection = ::Oxblood::Connection.new(config)

        new(connection)
      end

      def initialize(connection)
        @connection = connection
      end

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

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

      def disconnect
        @connection.socket.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)
      rescue ::Oxblood::RSocket::TimeoutError => e
        raise Redis::TimeoutError.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

9 entries across 9 versions & 1 rubygems

Version Path
oxblood-0.3.0 lib/redis/connection/oxblood.rb
oxblood-0.2.0 lib/redis/connection/oxblood.rb
oxblood-0.1.0 lib/redis/connection/oxblood.rb
oxblood-0.1.0.dev12 lib/redis/connection/oxblood.rb
oxblood-0.1.0.dev11 lib/redis/connection/oxblood.rb
oxblood-0.1.0.dev10 lib/redis/connection/oxblood.rb
oxblood-0.1.0.dev9 lib/redis/connection/oxblood.rb
oxblood-0.1.0.dev8 lib/redis/connection/oxblood.rb
oxblood-0.1.0.dev7 lib/redis/connection/oxblood.rb