Class: Rufus::Edo::NetTyrant
- Inherits:
-
Object
- Object
- Rufus::Edo::NetTyrant
- Includes:
- CabinetCore, Tokyo::TyrantCommons
- Defined in:
- lib/rufus/edo/ntyrant/abstract.rb
Overview
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 Tokyo::HashMethods
Instance Method Summary collapse
-
#compact_copy(target_path) ⇒ Object
Copies the current cabinet to a new file.
-
#copy(target_path) ⇒ Object
isn’t that a bit dangerous ? it creates a file on the server…
-
#ext(func_name, key = '', value = '', opts = {}) ⇒ Object
Calls a lua embedded function (tokyocabinet.sourceforge.net/tyrantdoc/#luaext).
-
#initialize(host, port = 0) ⇒ NetTyrant
constructor
Connects to a given Tokyo Tyrant server.
-
#weight ⇒ Object
Returns the ‘weight’ of the db (in bytes).
Methods included from Tokyo::TyrantCommons
Methods included from CabinetCore
#[]=, #clear, #close, #defrag, #delete, #delete_keys_with_prefix, included, #incr, #keys, #ldelete, #lget, #merge!, #original, #path, #putcat, #putkeep, #size, #sync, #tranabort, #tranbegin, #trancommit
Methods included from Tokyo::Transactions
Methods included from Tokyo::HashMethods
#[], #default, #default=, #each, #merge, #merge!, #to_a, #to_h, #values
Constructor Details
#initialize(host, port = 0) ⇒ NetTyrant
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 |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
48 49 50 |
# File 'lib/rufus/edo/ntyrant/abstract.rb', line 48 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
48 49 50 |
# File 'lib/rufus/edo/ntyrant/abstract.rb', line 48 def port @port end |
Instance Method Details
#compact_copy(target_path) ⇒ Object
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(target_path) ⇒ Object
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(func_name, key = '', value = '', opts = {}) ⇒ Object
Calls a lua embedded function (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 ⇒ Object
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 |