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
public instance
protected instance
Included modules
Attributes
| host | [R] | |
| port | [R] |
Public class methods
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
# 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
# File lib/rufus/tokyo/tyrant/table.rb, line 108 108: def abort #:nodoc# 109: raise_transaction_nme('abort') 110: end
using the cabinet lib
# File lib/rufus/tokyo/tyrant/table.rb, line 101 101: def lib 102: TyrantLib 103: end
# File lib/rufus/tokyo/tyrant/table.rb, line 117 117: def tranabort #:nodoc# 118: raise_transaction_nme('tranabort') 119: end
# File lib/rufus/tokyo/tyrant/table.rb, line 111 111: def tranbegin #:nodoc# 112: raise_transaction_nme('tranbegin') 113: end
# File lib/rufus/tokyo/tyrant/table.rb, line 114 114: def trancommit #:nodoc# 115: raise_transaction_nme('trancommit') 116: end
# File lib/rufus/tokyo/tyrant/table.rb, line 105 105: def transaction #:nodoc# 106: raise_transaction_nme('transaction') 107: end
Protected instance methods
Returns the raw stat string from the Tyrant server.
# 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
# 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