Class: Moneta::Adapters::Tyrant

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

Instance Method Summary collapse

Methods included from Defaults

#[]=, #fetch

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(options = {})
  @hash = ::TokyoTyrant::RDB.new

  if !@hash.open(options[:host], options[: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

#clearObject



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

Returns:

  • (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