Class: Async::Redis::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/async/redis/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint = Redis.local_endpoint, protocol = Protocol::RESP, **options) ⇒ Client

Returns a new instance of Client.



33
34
35
36
37
38
# File 'lib/async/redis/client.rb', line 33

def initialize(endpoint = Redis.local_endpoint, protocol = Protocol::RESP, **options)
  @endpoint = endpoint
  @protocol = protocol
  
  @connections = connect(**options)
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



40
41
42
# File 'lib/async/redis/client.rb', line 40

def endpoint
  @endpoint
end

#protocolObject (readonly)

Returns the value of attribute protocol.



41
42
43
# File 'lib/async/redis/client.rb', line 41

def protocol
  @protocol
end

Class Method Details

.open(*args, &block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/async/redis/client.rb', line 43

def self.open(*args, &block)
  client = self.new(*args)
  
  return client unless block_given?
  
  begin
    yield client
  ensure
    client.close
  end
end

Instance Method Details

#call(*arguments) ⇒ Object



59
60
61
62
63
64
# File 'lib/async/redis/client.rb', line 59

def call(*arguments)
  @connections.acquire do |connection|
    connection.write_request(arguments)
    return connection.read_response
  end
end

#closeObject



55
56
57
# File 'lib/async/redis/client.rb', line 55

def close
  @connections.close
end