lib/async/redis/client.rb in async-redis-0.9.0 vs lib/async/redis/client.rb in async-redis-0.10.0
- old
+ new
@@ -24,10 +24,69 @@
ServerError = ::Protocol::Redis::ServerError
class Client
include ::Protocol::Redis::Methods
+ module Methods
+ def subscribe(*channels)
+ context = Context::Subscribe.new(@pool, channels)
+
+ return context unless block_given?
+
+ begin
+ yield context
+ ensure
+ context.close
+ end
+ end
+
+ def transaction(&block)
+ context = Context::Transaction.new(@pool)
+
+ return context unless block_given?
+
+ begin
+ yield context
+ ensure
+ context.close
+ end
+ end
+
+ alias multi transaction
+
+ def pipeline(&block)
+ context = Context::Pipeline.new(@pool)
+
+ return context unless block_given?
+
+ begin
+ yield context
+ ensure
+ context.close
+ end
+ end
+
+ # Deprecated.
+ alias nested pipeline
+
+ def call(*arguments)
+ @pool.acquire do |connection|
+ connection.write_request(arguments)
+
+ connection.flush
+
+ return connection.read_response
+ end
+ end
+
+ def close
+ @pool.close
+ end
+ end
+
+ include Methods
+
def initialize(endpoint = Endpoint.local, protocol: endpoint.protocol, **options)
@endpoint = endpoint
@protocol = protocol
@pool = connect(**options)
@@ -36,76 +95,21 @@
attr :endpoint
attr :protocol
# @return [client] if no block provided.
# @yield [client, task] yield the client in an async task.
- def self.open(*arguments, &block)
- client = self.new(*arguments)
+ def self.open(*arguments, **options, &block)
+ client = self.new(*arguments, **options)
return client unless block_given?
Async do |task|
begin
yield client, task
ensure
client.close
end
end.wait
- end
-
- def close
- @pool.close
- end
-
- def subscribe(*channels)
- context = Context::Subscribe.new(@pool, channels)
-
- return context unless block_given?
-
- begin
- yield context
- ensure
- context.close
- end
- end
-
- def transaction(&block)
- context = Context::Transaction.new(@pool)
-
- return context unless block_given?
-
- begin
- yield context
- ensure
- context.close
- end
- end
-
- alias multi transaction
-
- def pipeline(&block)
- context = Context::Pipeline.new(@pool)
-
- return context unless block_given?
-
- begin
- yield context
- ensure
- context.close
- end
- end
-
- # Deprecated.
- alias nested pipeline
-
- def call(*arguments)
- @pool.acquire do |connection|
- connection.write_request(arguments)
-
- connection.flush
-
- return connection.read_response
- end
end
protected
def connect(**options)