lib/redic/client.rb in redic-0.0.8 vs lib/redic/client.rb in redic-1.0.0
- old
+ new
@@ -1,12 +1,15 @@
-require "redic/connection"
+require_relative "connection"
require "uri"
class Redic
class Client
- def initialize(url)
+ attr :timeout
+
+ def initialize(url, timeout)
@uri = URI.parse(url)
+ @timeout = timeout
@connection = nil
@semaphore = Mutex.new
end
def read
@@ -29,21 +32,31 @@
end
private
def establish_connection
begin
- @connection = Redic::Connection.new(@uri)
+ @connection = Redic::Connection.new(@uri, @timeout)
rescue StandardError => err
raise err, "Can't connect to: %s" % @uri
end
authenticate
+ select
end
def authenticate
if @uri.password
@semaphore.synchronize do
- write [:auth, @uri.password]
+ write ["AUTH", @uri.password]
+ read
+ end
+ end
+ end
+
+ def select
+ if @uri.path
+ @semaphore.synchronize do
+ write ["SELECT", @uri.path[1..-1]]
read
end
end
end