Class: Rufus::Edo::NetTyrantTable

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

INDEX_TYPES, META_TYPES

Constructor Summary

public initialize(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/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
[View source]


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 Method Details

abort

public abort

Meta Tags

Raises:

[NoMethodError]
[View source]


117
118
119
# File 'lib/rufus/edo/ntyrant/table.rb', line 117

def abort 
  raise NoMethodError.new("NetTyrant : transactions not supported")
end

ext

public ext(func_name, key = '', value = '', opts = {})

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.

[View source]


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

public lget(keys)

Also known as: mget

Gets multiple records in one sweep.

[View source]


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

public tranabort

Meta Tags

Raises:

[NoMethodError]
[View source]


126
127
128
# File 'lib/rufus/edo/ntyrant/table.rb', line 126

def tranabort 
  raise NoMethodError.new("NetTyrant : transactions not supported")
end

tranbegin

public tranbegin

Meta Tags

Raises:

[NoMethodError]
[View source]


120
121
122
# File 'lib/rufus/edo/ntyrant/table.rb', line 120

def tranbegin 
  raise NoMethodError.new("NetTyrant : transactions not supported")
end

trancommit

public trancommit

Meta Tags

Raises:

[NoMethodError]
[View source]


123
124
125
# File 'lib/rufus/edo/ntyrant/table.rb', line 123

def trancommit 
  raise NoMethodError.new("NetTyrant : transactions not supported")
end

transaction

public transaction

Meta Tags

Raises:

[NoMethodError]
[View source]


114
115
116
# File 'lib/rufus/edo/ntyrant/table.rb', line 114

def transaction 
  raise NoMethodError.new("NetTyrant : transactions not supported")
end
Generated on Friday, September 18 2009 at 10:35:38 AM by YARD 0.2.3.5 (ruby-1.8.7).