Class: Moneta::Adapters::Cassandra
- Inherits:
-
Object
- Object
- Moneta::Adapters::Cassandra
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/cassandra.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(options = {}) ⇒ Cassandra
constructor
A new instance of Cassandra.
- #key?(key) ⇒ Boolean
- #store(key, value) ⇒ Object
Methods included from Defaults
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( = {}) [:keyspace] ||= 'Moneta' [:host] ||= '127.0.0.1' [:port] ||= 9160 @client = ::Cassandra.new([:keyspace], "#{[:host]}:#{[:port]}") @column_family = [: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 |
#clear ⇒ Object
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
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 |