Class: Imperium::KV
Overview
A client for the KV API.
Constant Summary
Constants inherited from Client
Instance Attribute Summary
Attributes inherited from Client
Class Method Summary collapse
-
.delete(key, *options) ⇒ Object
DELETE a key using the Client.default_client.
-
.get(key, *options) ⇒ Object
GET a key using the Client.default_client.
-
.put(key, value, *options) ⇒ Object
Create or update a key using the Client.default_client.
Instance Method Summary collapse
-
#delete(key, *options) ⇒ KVDELETEResponse
Delete the specified key.
-
#get(key, *options) ⇒ KVGETResponse
Get the specified key/prefix using the supplied options.
-
#put(key, value, *options) ⇒ KVPUTResponse
Update or create the specified key.
-
#transaction(*options) {|a| ... } ⇒ TransactionResponse
Perform operation in the transaction.
Methods inherited from Client
default_client, inherited, #initialize, #path_prefix, reset_default_client, reset_default_clients
Constructor Details
This class inherits a constructor from Imperium::Client
Class Method Details
.delete(key, *options) ⇒ Object
DELETE a key using the Client.default_client
20 21 22 |
# File 'lib/imperium/kv.rb', line 20 def self.delete(key, *) default_client.delete(key, *) end |
.get(key, *options) ⇒ Object
GET a key using the Client.default_client
8 9 10 |
# File 'lib/imperium/kv.rb', line 8 def self.get(key, *) default_client.get(key, *) end |
.put(key, value, *options) ⇒ Object
Create or update a key using the Client.default_client
14 15 16 |
# File 'lib/imperium/kv.rb', line 14 def self.put(key, value, *) default_client.put(key, value, *) end |
Instance Method Details
#delete(key, *options) ⇒ KVDELETEResponse
Decide whether to support recursive deletion by accepting the :recurse parameter
Delete the specified key
123 124 125 126 127 128 |
# File 'lib/imperium/kv.rb', line 123 def delete(key, *) = () query_params = extract_query_params(, allowed_params: DELETE_ALLOWED_OPTIONS) response = @http_client.delete(prefix_path(key), query: query_params) KVDELETEResponse.new(response, options: ) end |
#get(key, *options) ⇒ KVGETResponse
Support blocking queries by accepting an :index parameter
Get the specified key/prefix using the supplied options.
61 62 63 64 65 66 |
# File 'lib/imperium/kv.rb', line 61 def get(key, *) = () query_params = extract_query_params(, allowed_params: GET_ALLOWED_OPTIONS) response = @http_client.get(prefix_path(key), query: query_params) KVGETResponse.new(response, prefix: key, options: ) end |
#put(key, value, *options) ⇒ KVPUTResponse
Update or create the specified key
100 101 102 103 104 105 |
# File 'lib/imperium/kv.rb', line 100 def put(key, value, *) = () query_params = extract_query_params(, allowed_params: PUT_ALLOWED_OPTIONS) response = @http_client.put(prefix_path(key), value, query: query_params) KVPUTResponse.new(response, options: ) end |
#transaction(*options) {|a| ... } ⇒ TransactionResponse
Perform operation in the transaction
This is useful when having a number of statements that must be executed
together or not at all.
141 142 143 144 145 146 147 148 |
# File 'lib/imperium/kv.rb', line 141 def transaction(*) = () query_params = extract_query_params() tx = Imperium::Transaction.new yield tx response = @http_client.put('v1/txn', tx.body, query: query_params) Imperium::TransactionResponse.new(response) end |