Class: Edamame::Store::TyrantStore
- Defined in:
- lib/edamame/store/tyrant_store.rb
Overview
Implementation of KeyStore with a Local TokyoCabinet table database (TDB)
Instance Attribute Summary collapse
-
#db_host ⇒ Object
Returns the value of attribute db_host.
-
#db_port ⇒ Object
Returns the value of attribute db_port.
Instance Method Summary collapse
- #close ⇒ Object
- #db ⇒ Object
- #include?(*args) ⇒ Boolean
-
#initialize(options) ⇒ TyrantStore
constructor
pass in the host:port uri of the key store.
-
#set_nr(key, val) ⇒ Object
Save the value into the database without waiting for a response.
- #size ⇒ Object
- #stats ⇒ Object
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 self.db_host, self.db_port = [:uri].to_s.split(':') super end |
Instance Attribute Details
#db_host ⇒ Object
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_port ⇒ Object
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
#close ⇒ Object
24 25 26 27 |
# File 'lib/edamame/store/tyrant_store.rb', line 24 def close @db.close if @db @db = nil end |
#db ⇒ Object
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
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 |
#size ⇒ Object
34 35 36 |
# File 'lib/edamame/store/tyrant_store.rb', line 34 def size() db.rnum end |
#stats ⇒ Object
38 39 40 |
# File 'lib/edamame/store/tyrant_store.rb', line 38 def stats { :size => size } end |