Class: Monkeyshines::Store::TyrantRdbKeyStore

Inherits:
TyrantRdbKeyStore
  • Object
show all
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

Instance Method Summary collapse

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 options
  raise "URI for #{self.class} is required" if options[:uri].blank?
  self.db_host, self.db_port = options[:uri].to_s.split(':')
  self.db_host.gsub!(/^(localhost|127\.0\.0\.1)$/,'')
  super options
end

Instance Attribute Details

#db_hostObject

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_portObject

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

#closeObject



26
27
28
29
# File 'lib/wukong/store/tyrant_rdb_key_store.rb', line 26

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

#dbObject



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

Returns:



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

#sizeObject



36
# File 'lib/wukong/store/tyrant_rdb_key_store.rb', line 36

def size()        db.rnum  end