Class: Edamame::Store::TyrantStore

Inherits:
Base
  • Object
show all
Defined in:
lib/edamame/store/tyrant_store.rb

Overview

Implementation of KeyStore with a Local TokyoCabinet table database (TDB)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], create, #delete, #each, #each_as, #get, #put, #save, #set

Constructor Details

#initialize(options) ⇒ TyrantStore

pass in the host:port uri of the key store.



12
13
14
15
# File 'lib/edamame/store/tyrant_store.rb', line 12

def initialize options
  self.db_host, self.db_port = options[:uri].to_s.split(':')
  super options
end

Instance Attribute Details

#db_hostObject

Returns the value of attribute db_host.



9
10
11
# File 'lib/edamame/store/tyrant_store.rb', line 9

def db_host
  @db_host
end

#db_portObject

Returns the value of attribute db_port.



9
10
11
# File 'lib/edamame/store/tyrant_store.rb', line 9

def db_port
  @db_port
end

Instance Method Details

#closeObject



24
25
26
27
# File 'lib/edamame/store/tyrant_store.rb', line 24

def close
  @db.close if @db
  @db = nil
end

#dbObject



17
18
19
20
21
22
# File 'lib/edamame/store/tyrant_store.rb', line 17

def db
  return @db if @db
  @db ||= TokyoTyrant::RDBTBL.new
  @db.open(db_host, db_port) or raise("Can't open DB #{db_host}:#{db_port}. Pass in host:port' #{@db.ecode}: #{@db.errmsg(@db.ecode)}")
  @db
end

#include?(*args) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/edamame/store/tyrant_store.rb', line 42

def include? *args
  db.has_key? *args
end

#set_nr(key, val) ⇒ Object

Save the value into the database without waiting for a response.



30
31
32
# File 'lib/edamame/store/tyrant_store.rb', line 30

def set_nr(key, val)
  db.putnr key, val if val
end

#sizeObject



34
35
36
# File 'lib/edamame/store/tyrant_store.rb', line 34

def size()
  db.rnum
end

#statsObject



38
39
40
# File 'lib/edamame/store/tyrant_store.rb', line 38

def stats
  {  :size => size }
end