Class: Rufus::Edo::NetTyrant

Connecting to a ‘classic’ Tokyo Tyrant server remotely

  require 'rufus/edo/ntyrant'
  t = Rufus::Edo::NetTyrant.new('127.0.0.1', 44001)
  t['toto'] = 'blah blah'
  t['toto'] # => 'blah blah'

Attributes

Instance Attributes

host [R] public

Returns the value of attribute host.

port [R] public

Returns the value of attribute port.

Constructor Summary

public initialize(host, port = 0)

Connects to a given Tokyo Tyrant server.

Note that if the port is not specified, the host parameter is expected to hold the path to a unix socket (not a TCP socket).

(You can start a unix socket listening Tyrant with :

   ttserver -host /tmp/tyrant_socket -port 0 data.tch

 and then connect to it with rufus-tokyo via :

   require 'rufus/edo/ntyrant'
   db = Rufus::Edo::NetTyrant.new('/tmp/tyrant_socket')
   db['a'] = 'alpha'
   db.close

)

To connect to a classic TCP bound Tyrant (port 44001) :

  t = Rufus::Edo::NetTyrant.new('127.0.0.1', 44001)
[View source]


71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rufus/edo/ntyrant/abstract.rb', line 71

def initialize (host, port=0)

  @host = host
  @port = port

  @db = TokyoTyrant::RDB.new
  @db.open(host, port) || raise_error

  if self.stat['type'] == 'table'

    @db.close

    raise ArgumentError.new(
      "tyrant at #{host}:#{port} is a table, " +
      "use Rufus::Edo::NetTyrantTable instead to access it.")
  end
end

Public Visibility

Public Instance Method Summary

#compact_copy(target_path)

Copies the current cabinet to a new file.

#copy(target_path)

isn’t that a bit dangerous ? it creates a file on the server.

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

Calls a lua embedded function (http://tokyocabinet.

#weight

Returns the ‘weight’ of the db (in bytes).

Public Instance Method Details

compact_copy

public compact_copy(target_path)

Copies the current cabinet to a new file.

Does it by copying each entry afresh to the target file. Spares some space, hence the ‘compact’ label…

Meta Tags

Raises:

[NotImplementedError]
[View source]


111
112
113
114
# File 'lib/rufus/edo/ntyrant/abstract.rb', line 111

def compact_copy (target_path)

  raise NotImplementedError.new('not creating files locally')
end

copy

public copy(target_path)

isn’t that a bit dangerous ? it creates a file on the server…

DISABLED.

[View source]


100
101
102
103
104
# File 'lib/rufus/edo/ntyrant/abstract.rb', line 100

def copy (target_path)

  #@db.copy(target_path)
  raise 'not allowed to create files on the server'
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]


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

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

  @db.ext(func_name.to_s, key.to_s, value.to_s, compute_ext_opts(opts))
end

weight

public weight

Returns the ‘weight’ of the db (in bytes)

[View source]


91
92
93
94
# File 'lib/rufus/edo/ntyrant/abstract.rb', line 91

def weight

  self.stat['size']
end
Generated on Friday, September 18 2009 at 10:35:38 AM by YARD 0.2.3.5 (ruby-1.8.7).