Class: Beachcomber::Client
- Inherits:
-
Object
- Object
- Beachcomber::Client
- Defined in:
- lib/beachcomber/client.rb
Overview
Client sends individual requests, opening a fresh socket connection for each call. For workloads that issue many queries per invocation, use #session to reuse a persistent connection.
Examples:
client = Beachcomber::Client.new
result = client.get('git.branch', path: '/repo')
puts result.data if result.hit?
Instance Method Summary collapse
-
#get(key, path: nil) ⇒ Result
Reads a cached value.
-
#initialize(socket_path: nil, timeout: DEFAULT_TIMEOUT) ⇒ Client
constructor
A new instance of Client.
-
#list ⇒ Result
Lists available providers registered with the daemon.
-
#poke(key, path: nil) ⇒ Object
Forces the daemon to recompute a provider/key.
-
#session {|Session| ... } ⇒ Object
Opens a persistent session and yields it to the block.
-
#status ⇒ Result
Returns scheduler and cache status from the daemon.
Constructor Details
#initialize(socket_path: nil, timeout: DEFAULT_TIMEOUT) ⇒ Client
Returns a new instance of Client.
125 126 127 128 |
# File 'lib/beachcomber/client.rb', line 125 def initialize(socket_path: nil, timeout: DEFAULT_TIMEOUT) @socket_path = socket_path || Discovery.socket_path @timeout = timeout end |
Instance Method Details
#get(key, path: nil) ⇒ Result
Reads a cached value.
137 138 139 140 141 |
# File 'lib/beachcomber/client.rb', line 137 def get(key, path: nil) req = { op: 'get', key: key } req[:path] = path if path roundtrip(req) end |
#list ⇒ Result
Lists available providers registered with the daemon.
159 160 161 |
# File 'lib/beachcomber/client.rb', line 159 def list roundtrip({ op: 'list' }) end |
#poke(key, path: nil) ⇒ Object
Forces the daemon to recompute a provider/key.
149 150 151 152 153 154 |
# File 'lib/beachcomber/client.rb', line 149 def poke(key, path: nil) req = { op: 'poke', key: key } req[:path] = path if path roundtrip(req) nil end |
#session {|Session| ... } ⇒ Object
Opens a persistent session and yields it to the block. The connection is closed automatically when the block returns (even on exception).
175 176 177 178 179 180 181 |
# File 'lib/beachcomber/client.rb', line 175 def session sock = dial session = Session.new(sock, @timeout) yield session ensure session&.close end |
#status ⇒ Result
Returns scheduler and cache status from the daemon.
166 167 168 |
# File 'lib/beachcomber/client.rb', line 166 def status roundtrip({ op: 'status' }) end |