Class Rufus::Tokyo::TyrantTable

  1. lib/rufus/tokyo/tyrant/table.rb

A Tokyo Cabinet table, but remote...

require 'rufus/tokyo/tyrant'
t = Rufus::Tokyo::Tyrant.new('127.0.0.1', 44001)
t['toto'] = { 'name' => 'toto the first', 'age' => '34' }
t['toto']
  # => { 'name' => 'toto the first', 'age' => '34' }

Most of the methods of this TyrantTable class are defined in the parent class Rufus::Tokyo::Table.

Methods

public class

  1. new

public instance

  1. abort
  2. lib
  3. tranabort
  4. tranbegin
  5. trancommit
  6. transaction

protected instance

  1. do_stat
  2. raise_transaction_nme

Included modules

  1. TyrantCommons
  2. Outlen
  3. Ext

Attributes

host [R]
port [R]

Public class methods

new (host, port=0)

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/tokyo/tyrant'
t = Rufus::Tokyo::TyrantTable.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/tokyo/tyrant'
t = Rufus::Tokyo::TyrantTable.new('/tmp/table_socket')
t['client0'] = { 'name' => 'Theodore Roosevelt', 'country' => 'usa' }
t.close
[show source]
    # File lib/rufus/tokyo/tyrant/table.rb, line 78
78:     def initialize (host, port=0)
79: 
80:       @db = lib.tcrdbnew
81: 
82:       @host = host
83:       @port = port
84: 
85:       (lib.tcrdbopen(@db, host, port) == 1) ||
86:         raise(TokyoError.new("couldn't connect to tyrant at #{host}:#{port}"))
87: 
88:       if self.stat['type'] != 'table'
89: 
90:         self.close
91: 
92:         raise ArgumentError.new(
93:           "tyrant at #{host}:#{port} is a not table, " +
94:           "use Rufus::Tokyo::Tyrant instead to access it.")
95:       end
96:     end

Public instance methods

abort (
[show source]
     # File lib/rufus/tokyo/tyrant/table.rb, line 108
108:     def abort #:nodoc#
109:       raise_transaction_nme('abort')
110:     end
lib ()

using the cabinet lib

[show source]
     # File lib/rufus/tokyo/tyrant/table.rb, line 101
101:     def lib
102:       TyrantLib
103:     end
tranabort (
[show source]
     # File lib/rufus/tokyo/tyrant/table.rb, line 117
117:     def tranabort #:nodoc#
118:       raise_transaction_nme('tranabort')
119:     end
tranbegin (
[show source]
     # File lib/rufus/tokyo/tyrant/table.rb, line 111
111:     def tranbegin #:nodoc#
112:       raise_transaction_nme('tranbegin')
113:     end
trancommit (
[show source]
     # File lib/rufus/tokyo/tyrant/table.rb, line 114
114:     def trancommit #:nodoc#
115:       raise_transaction_nme('trancommit')
116:     end
transaction (
[show source]
     # File lib/rufus/tokyo/tyrant/table.rb, line 105
105:     def transaction #:nodoc#
106:       raise_transaction_nme('transaction')
107:     end

Protected instance methods

do_stat ()

Returns the raw stat string from the Tyrant server.

[show source]
     # File lib/rufus/tokyo/tyrant/table.rb, line 139
139:     def do_stat
140: 
141:       lib.tcrdbstat(@db) # note : this is using tcrdbstat
142:     end
raise_transaction_nme (method_name)
[show source]
     # File lib/rufus/tokyo/tyrant/table.rb, line 131
131:     def raise_transaction_nme (method_name)
132: 
133:       raise NoMethodError.new(
134:         "Tyrant tables don't support transactions", method_name)
135:     end