Class: Rufus::Tokyo::TyrantTable
- Includes:
- Ext, NoTransactions, Outlen, TyrantCommons
- Defined in:
- lib/rufus/tokyo/tyrant/table.rb
Overview
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.
Constant Summary
Constants inherited from Table
Rufus::Tokyo::Table::INDEX_TYPES
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 HashMethods
Instance Method Summary collapse
-
#initialize(host, port = 0, params = {}) ⇒ TyrantTable
constructor
Connects to the Tyrant table listening at the given host and port.
-
#lib ⇒ Object
using the cabinet lib.
Methods included from NoTransactions
#abort, #tranabort, #tranbegin, #trancommit, #transaction
Methods included from Ext
Methods included from Outlen
Methods included from TyrantCommons
Methods inherited from Table
#[]=, #clear, #close, #delete, #delete_keys_with_prefix, #difference, #do_query, #generate_unique_id, #intersection, #keys, #lget, #path, #pointer, #prepare_query, #query, #query_count, #query_delete, #search, #set_index, #size, #tranabort, #tranbegin, #trancommit, #union
Methods included from Openable
Methods included from Transactions
Methods included from HashMethods
#[], #default, #default=, #each, #merge, #merge!, #to_a, #to_h, #values
Constructor Details
#initialize(host, port = 0, params = {}) ⇒ TyrantTable
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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/rufus/tokyo/tyrant/table.rb', line 78 def initialize (host, port=0, params={}) @db = lib.tcrdbnew @host = host @port = port lib.tcrdbopen(@db, host, port) || raise(TokyoError.new("couldn't connect to tyrant at #{host}:#{port}")) if self.stat['type'] != 'table' self.close raise ArgumentError.new( "tyrant at #{host}:#{port} is a not table, " + "use Rufus::Tokyo::Tyrant instead to access it.") end @default_proc = nil # # timeout and reconnect # defaults to two minutes timeout = params[:timeout] || 120.0 lib.tcrdbtune(@db, timeout, 1) end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
50 51 52 |
# File 'lib/rufus/tokyo/tyrant/table.rb', line 50 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
50 51 52 |
# File 'lib/rufus/tokyo/tyrant/table.rb', line 50 def port @port end |
Instance Method Details
#lib ⇒ Object
using the cabinet lib
111 112 113 |
# File 'lib/rufus/tokyo/tyrant/table.rb', line 111 def lib TyrantLib end |