Class: Rufus::Edo::NetTyrantTable
- Inherits:
-
Object
- Object
- Rufus::Edo::NetTyrantTable
- Includes:
- TableCore, Tokyo::TyrantCommons
- Defined in:
- lib/rufus/edo/ntyrant/table.rb
Overview
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.
Constant Summary
Constants included from TableCore
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Attributes included from Tokyo::HashMethods
Instance Method Summary collapse
-
#abort ⇒ Object
:nodoc#.
-
#initialize(host, port = 0) ⇒ NetTyrantTable
constructor
Connects to the Tyrant table listening at the given host and port.
-
#lget(keys) ⇒ Object
Gets multiple records in one sweep.
-
#tranabort ⇒ Object
:nodoc#.
-
#tranbegin ⇒ Object
:nodoc#.
-
#trancommit ⇒ Object
:nodoc#.
-
#transaction ⇒ Object
:nodoc#.
Methods included from Tokyo::TyrantCommons
Methods included from TableCore
#[]=, #clear, #close, #delete, #delete_keys_with_prefix, #generate_unique_id, #keys, #original, #prepare_query, #query, #query_delete, #set_index, #size
Methods included from Tokyo::HashMethods
#[], #default, #default=, #each, #merge, #merge!, #to_a, #to_h, #values
Constructor Details
#initialize(host, port = 0) ⇒ NetTyrantTable
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 |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
53 54 55 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 53 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
53 54 55 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 53 def port @port end |
Instance Method Details
#abort ⇒ Object
:nodoc#
115 116 117 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 115 def abort #:nodoc# raise NoMethodError.new("NetTyrant : transactions not supported") end |
#lget(keys) ⇒ Object
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 ⇒ Object
:nodoc#
124 125 126 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 124 def tranabort #:nodoc# raise NoMethodError.new("NetTyrant : transactions not supported") end |
#tranbegin ⇒ Object
:nodoc#
118 119 120 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 118 def tranbegin #:nodoc# raise NoMethodError.new("NetTyrant : transactions not supported") end |
#trancommit ⇒ Object
:nodoc#
121 122 123 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 121 def trancommit #:nodoc# raise NoMethodError.new("NetTyrant : transactions not supported") end |
#transaction ⇒ Object
:nodoc#
112 113 114 |
# File 'lib/rufus/edo/ntyrant/table.rb', line 112 def transaction #:nodoc# raise NoMethodError.new("NetTyrant : transactions not supported") end |