Class: Moneta::Adapters::Cassandra

Inherits:
Object
  • Object
show all
Includes:
Defaults
Defined in:
lib/moneta/adapters/cassandra.rb

Instance Method Summary collapse

Methods included from Defaults

#[]=, #fetch

Constructor Details

#initialize(options = {}) ⇒ Cassandra

Returns a new instance of Cassandra.



16
17
18
19
20
21
22
# File 'lib/moneta/adapters/cassandra.rb', line 16

def initialize(options = {})
  options[:keyspace] ||= 'Moneta'
  options[:host]     ||= '127.0.0.1'
  options[:port]     ||=  9160
  @client = ::Cassandra.new(options[:keyspace], "#{options[:host]}:#{options[:port]}")
  @column_family = options[:column_family] || :Moneta
end

Instance Method Details

#[](key) ⇒ Object



29
30
31
32
# File 'lib/moneta/adapters/cassandra.rb', line 29

def [](key)
  key = key_for(key)
  deserialize(@client.get(@column_family, key)['value'])
end

#clearObject



46
47
48
49
50
# File 'lib/moneta/adapters/cassandra.rb', line 46

def clear(*)
  @client.each_key(@column_family) do |key|
    delete(key)
  end
end

#delete(key) ⇒ Object



34
35
36
37
38
39
# File 'lib/moneta/adapters/cassandra.rb', line 34

def delete(key, *)
  key = key_for(key)
  value = self[key]
  @client.remove(@column_family, key)
  value
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/moneta/adapters/cassandra.rb', line 24

def key?(key, *)
  key = key_for(key)
  @client.exists?(@column_family, key)
end

#store(key, value) ⇒ Object



41
42
43
44
# File 'lib/moneta/adapters/cassandra.rb', line 41

def store(key, value, *)
  key = key_for(key)
  @client.insert(@column_family, key, {'value' => serialize(value)})
end