Class: Moneta::Adapters::Tyrant
- Inherits:
-
Object
- Object
- Moneta::Adapters::Tyrant
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/tyrant.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(options = {}) ⇒ Tyrant
constructor
A new instance of Tyrant.
- #key?(key) ⇒ Boolean
- #store(key, value) ⇒ Object
Methods included from Defaults
Constructor Details
#initialize(options = {}) ⇒ Tyrant
Returns a new instance of Tyrant.
13 14 15 16 17 18 19 |
# File 'lib/moneta/adapters/tyrant.rb', line 13 def initialize( = {}) @hash = ::TokyoTyrant::RDB.new if !@hash.open([:host], [:port]) puts @hash.errmsg(@hash.ecode) end end |
Instance Method Details
#[](key) ⇒ Object
25 26 27 |
# File 'lib/moneta/adapters/tyrant.rb', line 25 def [](key) deserialize(@hash[key_for(key)]) end |
#clear ⇒ Object
33 34 35 |
# File 'lib/moneta/adapters/tyrant.rb', line 33 def clear(*) @hash.clear end |
#delete(key) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/moneta/adapters/tyrant.rb', line 37 def delete(key, *) if value = self[key] @hash.delete(key_for(key)) value end end |
#key?(key) ⇒ Boolean
21 22 23 |
# File 'lib/moneta/adapters/tyrant.rb', line 21 def key?(key, *) !!self[key] end |
#store(key, value) ⇒ Object
29 30 31 |
# File 'lib/moneta/adapters/tyrant.rb', line 29 def store(key, value, *) @hash.put(key_for(key), serialize(value)) end |