Class: Monkeyshines::Store::TyrantRdbKeyStore
- Inherits:
-
TyrantRdbKeyStore
- Object
- TyrantRdbKeyStore
- Monkeyshines::Store::TyrantRdbKeyStore
- Defined in:
- lib/wukong/store/tyrant_rdb_key_store.rb,
lib/wukong/store/tyrant_tdb_key_store.rb
Overview
Implementation of KeyStore with a Local TokyoCabinet Table database (RDBTBL)
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) ⇒ TyrantRdbKeyStore
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
Constructor Details
#initialize(options) ⇒ TyrantRdbKeyStore
pass in the host:port uri of the key store.
12 13 14 15 16 17 |
# File 'lib/wukong/store/tyrant_rdb_key_store.rb', line 12 def initialize raise "URI for #{self.class} is required" if [:uri].blank? self.db_host, self.db_port = [:uri].to_s.split(':') self.db_host.gsub!(/^(localhost|127\.0\.0\.1)$/,'') super end |
Instance Attribute Details
#db_host ⇒ Object
Returns the value of attribute db_host.
9 10 11 |
# File 'lib/wukong/store/tyrant_rdb_key_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/wukong/store/tyrant_rdb_key_store.rb', line 9 def db_port @db_port end |
Instance Method Details
#close ⇒ Object
26 27 28 29 |
# File 'lib/wukong/store/tyrant_rdb_key_store.rb', line 26 def close @db.close if @db @db = nil end |
#db ⇒ Object
19 20 21 22 23 24 |
# File 'lib/wukong/store/tyrant_rdb_key_store.rb', line 19 def db return @db if @db @db ||= TokyoTyrant::RDB.new @db.open(db_host, db_port) or raise("Can't open DB at host #{db_host} port #{db_port}. Pass in host:port' #{@db.ecode}: #{@db.errmsg(@db.ecode)}") @db end |
#include?(*args) ⇒ Boolean
37 38 39 |
# File 'lib/wukong/store/tyrant_rdb_key_store.rb', line 37 def include? *args db.has_key? *args end |
#set_nr(key, val) ⇒ Object
Save the value into the database without waiting for a response.
32 33 34 |
# File 'lib/wukong/store/tyrant_rdb_key_store.rb', line 32 def set_nr(key, val) db.putnr key, val if val end |
#size ⇒ Object
36 |
# File 'lib/wukong/store/tyrant_rdb_key_store.rb', line 36 def size() db.rnum end |