Class: Rufus::Edo::NetTyrant
Included Modules
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
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)
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 Methods Included from Rufus::Edo::CabinetCore
[]=, clear, close, defrag, delete, delete_keys_with_prefix, incr, keys, ldelete, lget, merge!, original, path, putcat, putkeep, size, sync, tranabort, tranbegin, trancommit
Public Instance Methods Included from Rufus::Tokyo::TyrantCommons
Public Instance Method Details
compact_copy
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…
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
isn’t that a bit dangerous ? it creates a file on the server…
DISABLED.
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
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.
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
Returns the ‘weight’ of the db (in bytes)
91 92 93 94 |
# File 'lib/rufus/edo/ntyrant/abstract.rb', line 91 def weight self.stat['size'] end |