Class: Async::Redis::Client
- Inherits:
-
Object
- Object
- Async::Redis::Client
- Defined in:
- lib/async/redis/client.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
Class Method Summary collapse
Instance Method Summary collapse
- #call(*arguments) ⇒ Object
- #close ⇒ Object
-
#initialize(endpoint = Redis.local_endpoint, protocol = Protocol::RESP, **options) ⇒ Client
constructor
A new instance of Client.
- #multi(&block) ⇒ Object
- #publish(channel, message) ⇒ Object
- #subscribe(*channels) ⇒ Object
Constructor Details
#initialize(endpoint = Redis.local_endpoint, protocol = Protocol::RESP, **options) ⇒ Client
Returns a new instance of Client.
35 36 37 38 39 40 |
# File 'lib/async/redis/client.rb', line 35 def initialize(endpoint = Redis.local_endpoint, protocol = Protocol::RESP, **) @endpoint = endpoint @protocol = protocol @pool = connect(**) end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
42 43 44 |
# File 'lib/async/redis/client.rb', line 42 def endpoint @endpoint end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
43 44 45 |
# File 'lib/async/redis/client.rb', line 43 def protocol @protocol end |
Class Method Details
.open(*args, &block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/async/redis/client.rb', line 45 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
89 90 91 92 93 94 |
# File 'lib/async/redis/client.rb', line 89 def call(*arguments) @pool.acquire do |connection| connection.write_request(arguments) return connection.read_response end end |
#close ⇒ Object
57 58 59 |
# File 'lib/async/redis/client.rb', line 57 def close @pool.close end |
#multi(&block) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/async/redis/client.rb', line 77 def multi(&block) context = Context::Multi.new(@pool) return context unless block_given? begin yield context ensure context.close end end |
#publish(channel, message) ⇒ Object
61 62 63 |
# File 'lib/async/redis/client.rb', line 61 def publish(channel, ) call('PUBLISH', channel, ) end |
#subscribe(*channels) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/async/redis/client.rb', line 65 def subscribe(*channels) context = Context::Subscribe.new(@pool, channels) return context unless block_given? begin yield context ensure context.close end end |