Connecting to a ‘classic’ tyrant server remotely
require 'rufus/tokyo/tyrant'
t = Rufus::Tokyo::Tyrant.new('127.0.0.1', 44001)
t['toto'] = 'blah blah'
t['toto'] # => 'blah blah'
Included modules
Attributes
| host | [R] | |
| port | [R] |
Public class methods
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/tokyo/tyrant'
db = Rufus::Tokyo::Tyrant.new('/tmp/tyrant_socket')
db['a'] = 'alpha'
db.close
)
To connect to a classic TCP bound Tyrant (port 44001) :
t = Rufus::Tokyo::Tyrant.new('127.0.0.1', 44001)
# File lib/rufus/tokyo/tyrant/abstract.rb, line 66 66: def initialize (host, port=0) 67: 68: @db = lib.tcrdbnew 69: 70: @host = host 71: @port = port 72: 73: (lib.tcrdbopen(@db, host, port) == 1) || raise( 74: TokyoError.new("couldn't connect to tyrant at #{host}:#{port}")) 75: 76: if self.stat['type'] == 'table' 77: 78: self.close 79: 80: raise ArgumentError.new( 81: "tyrant at #{host}:#{port} is a table, " + 82: "use Rufus::Tokyo::TyrantTable instead to access it.") 83: end 84: end
Public instance methods
isn’t that a bit dangerous ? it creates a file on the server...
DISABLED.
# File lib/rufus/tokyo/tyrant/abstract.rb, line 97 97: def copy (target_path) 98: 99: #@db.copy(target_path) 100: raise 'not allowed to create files on the server' 101: end
Using the tyrant lib
# File lib/rufus/tokyo/tyrant/abstract.rb, line 88 88: def lib 89: 90: TyrantLib 91: end
Protected instance methods
# File lib/rufus/tokyo/tyrant/abstract.rb, line 110 110: def do_call_misc (function, list_pointer) 111: 112: lib.tcrdbmisc(@db, function, 0, list_pointer) 113: # opts always to 0 for now 114: end
Returns the raw stat string from the Tyrant server.
# File lib/rufus/tokyo/tyrant/abstract.rb, line 118 118: def do_stat 119: 120: lib.tcrdbstat(@db) 121: end