Class: Rollout::DynamoDB::Storage
- Inherits:
-
Object
- Object
- Rollout::DynamoDB::Storage
- Defined in:
- lib/rollout/dynamodb/storage.rb
Overview
This class implements the Storage API for Rollout
Instance Method Summary collapse
-
#del(key) ⇒ Object
Deletes a key (String) from DynamoDB.
-
#get(key) ⇒ Object
Gets the value (String) of a key (String) from DynamoDB.
-
#initialize(aws_access_key, aws_secret_key, table_name, region, options = {}) ⇒ Storage
constructor
‘options` is a Hash which may include: * `:connection_options` - a Hash which may in turn include: * `:connect_timeout` - Connection timeout to DynamoDB in seconds (default: `3`) * `:read_timeout` - Read timeout to DynamoDB in seconds (default: `3`) * `:write_timeout` - Write timeout to DynamoDB in seconds (default: `3`) * `:retry_limit` - Number of times to retry HTTP requests to DynamoDB (default: `4`).
-
#list ⇒ Object
Returns an ‘Array` of keys (`String`) from DynamoDB.
-
#set(key, value) ⇒ Object
Sets the value (String) of a key (String) in DynamoDB.
Constructor Details
#initialize(aws_access_key, aws_secret_key, table_name, region, options = {}) ⇒ Storage
‘options` is a Hash which may include:
-
‘:connection_options` - a Hash which may in turn include:
* `:connect_timeout` - Connection timeout to DynamoDB in seconds (default: `3`) * `:read_timeout` - Read timeout to DynamoDB in seconds (default: `3`) * `:write_timeout` - Write timeout to DynamoDB in seconds (default: `3`) * `:retry_limit` - Number of times to retry HTTP requests to DynamoDB (default: `4`)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rollout/dynamodb/storage.rb', line 19 def initialize(aws_access_key, aws_secret_key, table_name, region, = {}) @aws_access_key = aws_access_key @aws_secret_key = aws_secret_key @table_name = table_name @region = region @options = # timeouts are expressed in seconds @options[:connection_options] ||= {} @options[:connection_options][:connect_timeout] ||= 3 @options[:connection_options][:read_timeout] ||= 3 @options[:connection_options][:write_timeout] ||= 3 @options[:connection_options][:retry_limit] ||= 4 end |
Instance Method Details
#del(key) ⇒ Object
Deletes a key (String) from DynamoDB. Returns ‘true` on success or raises an exception on errror
53 54 55 56 |
# File 'lib/rollout/dynamodb/storage.rb', line 53 def del(key) response = db.delete_item(@table_name, {'HashKeyElement' => {'S' => key}}) true end |
#get(key) ⇒ Object
Gets the value (String) of a key (String) from DynamoDB. Returns the value or raises an exception on error
37 38 39 40 |
# File 'lib/rollout/dynamodb/storage.rb', line 37 def get(key) response = db.get_item(@table_name, {'HashKeyElement' => {'S' => key}}) get_item_from_body(response.body) end |
#list ⇒ Object
Returns an ‘Array` of keys (`String`) from DynamoDB. Not used by the Storage API, but provided as a convenience and used in tests.
61 62 63 64 |
# File 'lib/rollout/dynamodb/storage.rb', line 61 def list response = db.scan(@table_name) response.body['Items'].map { |x| get_key_from_result(x) } end |
#set(key, value) ⇒ Object
Sets the value (String) of a key (String) in DynamoDB. Returns ‘true` on success, raises an exception on error
45 46 47 48 |
# File 'lib/rollout/dynamodb/storage.rb', line 45 def set(key, value) response = db.put_item(@table_name, {'id' => {'S' => key}, 'value' => {'S' => value}}) true end |