Parent

Included Modules

Files

Class/Module Index [+]

Quicksearch

Moneta::Adapters::HBase

HBase thrift backend @api public

Attributes

backend[R]

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

# File lib/moneta/adapters/hbase.rb, line 24
def initialize(options = {})
  options[:column] ||= 'value'
  options[:table] ||= 'moneta'
  cf = (options[:column_family] || 'moneta')
  @column = "#{cf}:#{options[:column]}"
  @backend = options[:backend] ||
    HBaseRb::Client.new(options[:host] || '127.0.0.1', options[:port] || '9090')
  @backend.create_table(options[:table], cf) unless @backend.has_table?(options[:table])
  @table = @backend.get_table(options[:table])
end

Public Instance Methods

clear(options = {}) click to toggle source

(see Proxy#clear)

# File lib/moneta/adapters/hbase.rb, line 69
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 77
def close
  @backend.close
  nil
end
delete(key, options = {}) click to toggle source

(see Proxy#delete)

# File lib/moneta/adapters/hbase.rb, line 61
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 53
def increment(key, amount = 1, options = {})
  result = @table.atomic_increment(key, @column, amount)
  # HACK: Throw error if applied to invalid value
  Utils.to_int(load(key)) if result == 0
  result
end
key?(key, options = {}) click to toggle source

(see Proxy#key?)

# File lib/moneta/adapters/hbase.rb, line 36
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 41
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 47
def store(key, value, options = {})
  @table.mutate_row(key, @column => pack(value))
  value
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.