Class: Async::Redis::Client
- Inherits:
-
Object
- Object
- Async::Redis::Client
- Includes:
- Protocol::Redis::Methods
- Defined in:
- lib/async/redis/client.rb
Direct Known Subclasses
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
-
.open(*arguments) {|client, task| ... } ⇒ client
If no block provided.
Instance Method Summary collapse
- #call(*arguments) ⇒ Object
- #close ⇒ Object
-
#initialize(endpoint = Redis.local_endpoint, protocol = Protocol::RESP2, **options) ⇒ Client
constructor
A new instance of Client.
- #pipeline(&block) ⇒ Object (also: #nested)
- #publish(channel, message) ⇒ Object
- #subscribe(*channels) ⇒ Object
- #transaction(&block) ⇒ Object (also: #multi)
Constructor Details
#initialize(endpoint = Redis.local_endpoint, protocol = Protocol::RESP2, **options) ⇒ Client
Returns a new instance of Client.
47 48 49 50 51 52 |
# File 'lib/async/redis/client.rb', line 47 def initialize(endpoint = Redis.local_endpoint, protocol = Protocol::RESP2, **) @endpoint = endpoint @protocol = protocol @pool = connect(**) end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
54 55 56 |
# File 'lib/async/redis/client.rb', line 54 def endpoint @endpoint end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
55 56 57 |
# File 'lib/async/redis/client.rb', line 55 def protocol @protocol end |
Class Method Details
.open(*arguments) {|client, task| ... } ⇒ client
Returns if no block provided.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# 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 |
Instance Method Details
#call(*arguments) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/async/redis/client.rb', line 122 def call(*arguments) @pool.acquire do |connection| connection.write_request(arguments) connection.flush return connection.read_response end end |
#close ⇒ Object
73 74 75 |
# File 'lib/async/redis/client.rb', line 73 def close @pool.close end |
#pipeline(&block) ⇒ Object Also known as: nested
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/async/redis/client.rb', line 107 def pipeline(&block) context = Context::Pipeline.new(@pool) return context unless block_given? begin yield context ensure context.close end end |
#publish(channel, message) ⇒ Object
77 78 79 |
# File 'lib/async/redis/client.rb', line 77 def publish(channel, ) call('PUBLISH', channel, ) end |
#subscribe(*channels) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/async/redis/client.rb', line 81 def subscribe(*channels) context = Context::Subscribe.new(@pool, channels) return context unless block_given? begin yield context ensure context.close end end |
#transaction(&block) ⇒ Object Also known as: multi
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/async/redis/client.rb', line 93 def transaction(&block) context = Context::Transaction.new(@pool) return context unless block_given? begin yield context ensure context.close end end |