Parent

Files

Class/Module Index [+]

Quicksearch

Moneta::Adapters::TokyoTyrant

TokyoTyrant backend @api public

Attributes

backend[R]

Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [String] :host ('127.0.0.1') Server host name @option options [Integer] :port (1978) Server port @option options [::TokyoTyrant::RDB] :backend Use existing backend instance

# File lib/moneta/adapters/tokyotyrant.rb, line 24
def initialize(options = {})
  options[:host] ||= '127.0.0.1'
  options[:port] ||= 1978
  if options[:backend]
    @backend = options[:backend]
  elsif defined?(::TokyoTyrant::RDB)
    # Use ruby client
    @backend = ::TokyoTyrant::RDB.new
    @backend.open(options[:host], options[:port]) or raise @backend.errmsg(@backend.ecode)
  else
    # Use native client
    @backend = ::TokyoTyrant::DB.new(options[:host], options[:port])
  end
  @native = @backend.class.name != 'TokyoTyrant::RDB'
  probe = '__tokyotyrant_endianness_probe'
  @backend.delete(probe)
  @backend.addint(probe, 1)
  @pack = @backend.delete(probe) == [1].pack('l>') ? 'l>' : 'l<'
end

Public Instance Methods

close() click to toggle source

(see Proxy#close)

# File lib/moneta/adapters/tokyotyrant.rb, line 85
def close
  @backend.close
  nil
end
create(key, value, options = {}) click to toggle source

(see Proxy#create)

# File lib/moneta/adapters/tokyotyrant.rb, line 71
def create(key, value, options = {})
  if @native
    begin
      # Native client throws an exception
      @backend.putkeep(key, pack(value))
    rescue TokyoTyrantError
      false
    end
  else
    @backend.putkeep(key, pack(value))
  end
end
delete(key, options = {}) click to toggle source

(see Proxy#delete)

# File lib/moneta/adapters/tokyotyrant.rb, line 57
def delete(key, options = {})
  value = load(key, options)
  if value
    @backend.delete(key)
    value
  end
end
increment(key, amount = 1, options = {}) click to toggle source

(see Proxy#increment)

# File lib/moneta/adapters/tokyotyrant.rb, line 66
def increment(key, amount = 1, options = {})
  @backend.addint(key, amount) || raise('Tried to increment non integer value')
end
load(key, options = {}) click to toggle source

(see Proxy#load)

# File lib/moneta/adapters/tokyotyrant.rb, line 45
def load(key, options = {})
  value = @backend[key]
  value && unpack(value)
end
store(key, value, options = {}) click to toggle source

(see Proxy#store)

# File lib/moneta/adapters/tokyotyrant.rb, line 51
def store(key, value, options = {})
  @backend[key] = pack(value)
  value
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.