Class: Rufus::Edo::NetTyrantTable
Included Modules
A Tokyo Cabinet table, but remote…
require 'rufus/edo/ntyrant' t = Rufus::Edo::NetTyrant.new('127.0.0.1', 44001) t['toto'] = { 'name' => 'toto the first', 'age' => '34' } t['toto'] # => { 'name' => 'toto the first', 'age' => '34' }
NOTE : The advantage of this class is that it leverages the TokyoTyrant.rb provided by Hirabayashi-san. It’s pure Ruby, it’s slow but works everywhere without the need for Tokyo Cabinet and Tyrant C libraries.
Attributes
Instance Attributes
| host | [R] | public |
Returns the value of attribute host. |
|---|---|---|---|
| port | [R] | public |
Returns the value of attribute port. |
Constants Included from Rufus::Edo::TableCore
Constructor Summary
Connects to the Tyrant table listening at the given host and port.
You start such a Tyrant with :
ttserver -port 44502 data.tct
and then :
require 'rufus/edo/ntyrant' t = Rufus::Edo::NetTyrantTable.new('127.0.0.1', 44502) t['client0'] = { 'name' => 'Heike no Kyomori', 'country' => 'jp' } t.close
You can start a Tokyo Tyrant and make it listen to a unix socket (not TCP) with :
ttserver -host /tmp/table_socket -port 0 data.tct
then :
require 'rufus/edo/ntyrant' t = Rufus::Edo::NetTyrantTable.new('/tmp/table_socket') t['client0'] = { 'name' => 'Theodore Roosevelt', 'country' => 'usa' } t.close
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 82 def initialize (host, port=0) @host = host @port = port @db = TokyoTyrant::RDBTBL.new @db.open(host, port) || raise_error if self.stat['type'] != 'table' @db.close raise ArgumentError.new( "tyrant at #{host}:#{port} is not a table, " + "use Rufus::Edo::NetTyrant instead to access it.") end end |
Public Visibility
Public Instance Method Summary
| #abort | |
|---|---|
| #ext(func_name, key = '', value = '', opts = {}) |
Calls a lua embedded function (http://tokyocabinet. |
| #lget(keys) #mget |
Gets multiple records in one sweep. |
| #tranabort | |
| #tranbegin | |
| #trancommit | |
| #transaction |
Public Instance Methods Included from Rufus::Edo::TableCore
[]=, clear, close, delete, delete_keys_with_prefix, difference, generate_unique_id, intersection, keys, original, prepare_query, query, query_delete, search, set_index, size, union
Public Instance Methods Included from Rufus::Tokyo::TyrantCommons
Public Instance Method Details
abort
117 118 119 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 117 def abort raise NoMethodError.new("NetTyrant : transactions not supported") end |
ext
Calls a lua embedded function (http://tokyocabinet.sourceforge.net/tyrantdoc/#luaext)
Options are :global_locking and :record_locking
Returns the return value of the called function.
Nil is returned in case of failure.
139 140 141 142 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 139 def ext (func_name, key='', value='', opts={}) @db.ext(func_name.to_s, key.to_s, value.to_s, compute_ext_opts(opts)) end |
lget
Also known as: mget
Gets multiple records in one sweep.
102 103 104 105 106 107 108 109 110 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 102 def lget (keys) h = keys.inject({}) { |h, k| h[k] = nil; h } r = @db.mget(h) raise 'lget failure' if r == -1 h end |
tranabort
126 127 128 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 126 def tranabort raise NoMethodError.new("NetTyrant : transactions not supported") end |
tranbegin
120 121 122 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 120 def tranbegin raise NoMethodError.new("NetTyrant : transactions not supported") end |
trancommit
123 124 125 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 123 def trancommit raise NoMethodError.new("NetTyrant : transactions not supported") end |
transaction
114 115 116 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 114 def transaction raise NoMethodError.new("NetTyrant : transactions not supported") end |