Class: Rufus::Tokyo::Tyrant

Inherits:
Cabinet
  • Object
show all
Includes:
Ext, TyrantCommons
Defined in:
lib/rufus/tokyo/tyrant/abstract.rb

Overview

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'

Instance Attribute Summary collapse

Attributes included from HashMethods

#default_proc

Instance Method Summary collapse

Methods included from Ext

#ext

Methods included from TyrantCommons

#compute_ext_opts, #stat

Methods inherited from Cabinet

#[]=, #clear, #close, #compact_copy, #defrag, #delete, #delete_keys_with_prefix, #get4, #incr, #keys, #ldelete, #lget, #merge!, new_hash, new_tree, open, #path, #putcat, #putdup, #putkeep, #size, #sync, #tranabort, #tranbegin, #trancommit, #weight

Methods included from Outlen

#outlen_op

Methods included from Transactions

#abort, #transaction

Methods included from HashMethods

#[], #default, #default=, #each, #merge, #merge!, #to_a, #to_h, #values

Constructor Details

#initialize(host, port = 0) ⇒ Tyrant

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)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rufus/tokyo/tyrant/abstract.rb', line 66

def initialize (host, port=0)

  @db = lib.tcrdbnew

  @host = host
  @port = port

  (lib.tcrdbopen(@db, host, port) == 1) || raise(
    TokyoError.new("couldn't connect to tyrant at #{host}:#{port}"))

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

    self.close

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

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



43
44
45
# File 'lib/rufus/tokyo/tyrant/abstract.rb', line 43

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



43
44
45
# File 'lib/rufus/tokyo/tyrant/abstract.rb', line 43

def port
  @port
end

Instance Method Details

#copy(target_path) ⇒ Object

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

DISABLED.



97
98
99
100
101
# File 'lib/rufus/tokyo/tyrant/abstract.rb', line 97

def copy (target_path)

  #@db.copy(target_path)
  raise 'not allowed to create files on the server'
end

#libObject

Using the tyrant lib



88
89
90
91
# File 'lib/rufus/tokyo/tyrant/abstract.rb', line 88

def lib

  TyrantLib
end