class Async::Redis::Client
Attributes
endpoint[R]
protocol[R]
Public Class Methods
new(endpoint = Redis.local_endpoint, protocol: Protocol::RESP2, **options)
click to toggle source
# File lib/async/redis/client.rb, line 47 def initialize(endpoint = Redis.local_endpoint, protocol: Protocol::RESP2, **options) @endpoint = endpoint @protocol = protocol @pool = connect(**options) end
open(*arguments) { |client, task| ... }
click to toggle source
@return [client] if no block provided. @yield [client, task] yield the client in an async task.
# File lib/async/redis/client.rb, line 59 def self.open(*arguments, &block) client = self.new(*arguments) return client unless block_given? Async do |task| begin yield client, task ensure client.close end end.wait end
Public Instance Methods
call(*arguments)
click to toggle source
# File lib/async/redis/client.rb, line 118 def call(*arguments) @pool.acquire do |connection| connection.write_request(arguments) connection.flush return connection.read_response end end
close()
click to toggle source
# File lib/async/redis/client.rb, line 73 def close @pool.close end
pipeline() { |context| ... }
click to toggle source
# File lib/async/redis/client.rb, line 103 def pipeline(&block) context = Context::Pipeline.new(@pool) return context unless block_given? begin yield context ensure context.close end end
Also aliased as: nested
subscribe(*channels) { |context| ... }
click to toggle source
# File lib/async/redis/client.rb, line 77 def subscribe(*channels) context = Context::Subscribe.new(@pool, channels) return context unless block_given? begin yield context ensure context.close end end
transaction() { |context| ... }
click to toggle source
# File lib/async/redis/client.rb, line 89 def transaction(&block) context = Context::Transaction.new(@pool) return context unless block_given? begin yield context ensure context.close end end
Also aliased as: multi
Protected Instance Methods
connect(**options)
click to toggle source
# File lib/async/redis/client.rb, line 130 def connect(**options) Async::Pool::Controller.wrap(**options) do peer = @endpoint.connect # We will manage flushing ourselves: peer.sync = true stream = IO::Stream.new(peer) @protocol.client(stream) end end