Class: Moneta::Adapters::HBase
- Inherits:
-
Base
- Object
- Base
- Moneta::Adapters::HBase
show all
- Defined in:
- lib/moneta/adapters/hbase.rb
Overview
Instance Method Summary
collapse
Methods inherited from Base
#[], #[]=, #decrement, #fetch
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ HBase
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/moneta/adapters/hbase.rb', line 16
def initialize(options = {})
options[:host] ||= '127.0.0.1'
options[:port] ||= '9090'
options[:table] ||= 'moneta'
options[:column] ||= 'value'
cf = (options[:column_family] || 'moneta')
@db = HBaseRb::Client.new(options[:host], options[:port])
@db.create_table(options[:table], cf) unless @db.has_table?(options[:table])
@table = @db.get_table(options[:table])
@column = "#{cf}:#{options[:column]}"
end
|
Instance Method Details
#clear(options = {}) ⇒ Object
59
60
61
62
63
64
|
# File 'lib/moneta/adapters/hbase.rb', line 59
def clear(options = {})
@table.create_scanner do |row|
@table.delete_row(row.row)
end
self
end
|
#close ⇒ Object
66
67
68
69
|
# File 'lib/moneta/adapters/hbase.rb', line 66
def close
@db.close
nil
end
|
#delete(key, options = {}) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/moneta/adapters/hbase.rb', line 52
def delete(key, options = {})
if value = load(key, options)
@table.delete_row(key)
unpack(value)
end
end
|
#increment(key, amount = 1, options = {}) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/moneta/adapters/hbase.rb', line 42
def increment(key, amount = 1, options = {})
result = @table.atomic_increment(key, @column, amount)
if result == 0
value = load(key)
raise 'Tried to increment non integer value' unless value.to_s == value.to_i.to_s
end
result
end
|
#key?(key, options = {}) ⇒ Boolean
28
29
30
|
# File 'lib/moneta/adapters/hbase.rb', line 28
def key?(key, options = {})
@table.get(key, @column).first != nil
end
|
#load(key, options = {}) ⇒ Object
32
33
34
35
|
# File 'lib/moneta/adapters/hbase.rb', line 32
def load(key, options = {})
cell = @table.get(key, @column).first
cell && unpack(cell.value)
end
|
#store(key, value, options = {}) ⇒ Object
37
38
39
40
|
# File 'lib/moneta/adapters/hbase.rb', line 37
def store(key, value, options = {})
@table.mutate_row(key, @column => pack(value))
value
end
|