Class: Moneta::Adapters::HBase
- Inherits:
-
Moneta::Adapter
- Object
- Moneta::Adapter
- Moneta::Adapters::HBase
- Defined in:
- lib/moneta/adapters/hbase.rb
Overview
HBase thrift backend
Instance Attribute Summary
Attributes inherited from Moneta::Adapter
Instance Method Summary collapse
-
#clear(options = {}) ⇒ void
Clear all keys in this store.
-
#close ⇒ Object
Explicitly close the store.
-
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value.
-
#increment(key, amount = 1, options = {}) ⇒ Object
Atomically increment integer value with key.
-
#initialize(options = {}) ⇒ HBase
constructor
A new instance of HBase.
-
#key?(key, options = {}) ⇒ Boolean
Exists the value with key.
-
#load(key, options = {}) ⇒ Object
Fetch value with key.
-
#store(key, value, options = {}) ⇒ Object
Store value with key.
Methods inherited from Moneta::Adapter
backend, backend_block, backend_required?
Methods included from Config
Methods included from Defaults
#[], #[]=, #create, #decrement, #each_key, #features, #fetch, #fetch_values, included, #merge!, #slice, #supports?, #update, #values_at
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ HBase
Returns a new instance of HBase.
26 27 28 29 30 31 |
# File 'lib/moneta/adapters/hbase.rb', line 26 def initialize( = {}) super @column = [config.column_family, config.column].join(':') backend.create_table(config.table, config.column_family) unless backend.has_table?(config.table) @table = backend.get_table(config.table) end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
67 68 69 70 71 72 |
# File 'lib/moneta/adapters/hbase.rb', line 67 def clear( = {}) @table.create_scanner do |row| @table.delete_row(row.row) end self end |
#close ⇒ Object
Explicitly close the store
75 76 77 78 |
# File 'lib/moneta/adapters/hbase.rb', line 75 def close backend.close nil end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
59 60 61 62 63 64 |
# File 'lib/moneta/adapters/hbase.rb', line 59 def delete(key, = {}) if value = load(key, ) @table.delete_row(key) value end end |
#increment(key, amount = 1, options = {}) ⇒ Object
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Atomically increment integer value with key
This method also accepts negative amounts.
51 52 53 54 55 56 |
# File 'lib/moneta/adapters/hbase.rb', line 51 def increment(key, amount = 1, = {}) result = @table.atomic_increment(key, @column, amount) # HACK: Throw error if applied to invalid value Integer(load(key)) if result == 0 result end |
#key?(key, options = {}) ⇒ Boolean
Exists the value with key
34 35 36 |
# File 'lib/moneta/adapters/hbase.rb', line 34 def key?(key, = {}) @table.get(key, @column).first != nil end |
#load(key, options = {}) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
39 40 41 42 |
# File 'lib/moneta/adapters/hbase.rb', line 39 def load(key, = {}) cell = @table.get(key, @column).first cell && unpack(cell.value) end |
#store(key, value, options = {}) ⇒ Object
Store value with key
45 46 47 48 |
# File 'lib/moneta/adapters/hbase.rb', line 45 def store(key, value, = {}) @table.mutate_row(key, @column => pack(value)) value end |