class Moneta::Adapters::HBase
HBase
thrift backend @api public
Public Class Methods
new(options = {})
click to toggle source
@param [Hash] options @option options [String] :host (‘127.0.0.1’) Server
host name @option options [Integer] :port (9090) Server
port @option options [String] :table (‘moneta’) Table name @option options [String] :column_family (‘moneta’) Column family @option options [String] :column (‘value’) Column @option options [::HBaseRb::Client] :backend Use existing backend instance
Calls superclass method
Moneta::Adapter::new
# File lib/moneta/adapters/hbase.rb, line 26 def initialize(options = {}) 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
Public Instance Methods
clear(options = {})
click to toggle source
(see Proxy#clear
)
# File lib/moneta/adapters/hbase.rb, line 67 def clear(options = {}) @table.create_scanner do |row| @table.delete_row(row.row) end self end
close()
click to toggle source
(see Proxy#close
)
# File lib/moneta/adapters/hbase.rb, line 75 def close backend.close nil end
delete(key, options = {})
click to toggle source
(see Proxy#delete
)
# File lib/moneta/adapters/hbase.rb, line 59 def delete(key, options = {}) if value = load(key, options) @table.delete_row(key) value end end
increment(key, amount = 1, options = {})
click to toggle source
(see Proxy#increment
)
# File lib/moneta/adapters/hbase.rb, line 51 def increment(key, amount = 1, options = {}) 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 = {})
click to toggle source
(see Proxy#key?
)
# File lib/moneta/adapters/hbase.rb, line 34 def key?(key, options = {}) @table.get(key, @column).first != nil end
load(key, options = {})
click to toggle source
(see Proxy#load
)
# File lib/moneta/adapters/hbase.rb, line 39 def load(key, options = {}) cell = @table.get(key, @column).first cell && unpack(cell.value) end
store(key, value, options = {})
click to toggle source
(see Proxy#store
)
# File lib/moneta/adapters/hbase.rb, line 45 def store(key, value, options = {}) @table.mutate_row(key, @column => pack(value)) value end
Private Instance Methods
pack(value)
click to toggle source
# File lib/moneta/adapters/hbase.rb, line 82 def pack(value) intvalue = value.to_i if intvalue >= 0 && intvalue <= 0xFFFFFFFFFFFFFFFF && intvalue.to_s == value # Pack as 8 byte big endian [intvalue].pack('Q>') elsif value.bytesize >= 8 # Add nul character to make value distinguishable from integer value + "\0" else value end end
unpack(value)
click to toggle source
# File lib/moneta/adapters/hbase.rb, line 95 def unpack(value) if value.bytesize == 8 # Unpack 8 byte big endian value.unpack1('Q>').to_s elsif value.bytesize >= 9 && value[-1] == ?\0 # Remove nul character value[0..-2] else value end end