class Moneta::Adapters::Client

Moneta client backend @api public

Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [Integer] :port (9000) TCP port @option options [String] :host ('127.0.0.1') Hostname @option options [String] :socket Unix socket file name as alternative to `:port` and `:host`

# File lib/moneta/adapters/client.rb, line 14
def initialize(options = {})
  @socket = options[:socket] ? UNIXSocket.open(options[:socket]) :
    TCPSocket.open(options[:host] || '127.0.0.1', options[:port] || 9000)
end

Public Instance Methods

clear(options = {}) click to toggle source

(see Moneta::Proxy#clear)

# File lib/moneta/adapters/client.rb, line 57
def clear(options = {})
  write(:clear, options)
  read
  self
end
close() click to toggle source

(see Moneta::Proxy#close)

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

(see Moneta::Proxy#create)

# File lib/moneta/adapters/client.rb, line 51
def create(key, value, options = {})
  write(:create, key, value, options)
  read
end
delete(key, options = {}) click to toggle source

(see Moneta::Proxy#delete)

# File lib/moneta/adapters/client.rb, line 39
def delete(key, options = {})
  write(:delete, key, options)
  read
end
features() click to toggle source

(see Default#features)

# File lib/moneta/adapters/client.rb, line 70
def features
  @features ||=
    begin
      write(:features)
      read.freeze
    end
end
increment(key, amount = 1, options = {}) click to toggle source

(see Moneta::Proxy#increment)

# File lib/moneta/adapters/client.rb, line 45
def increment(key, amount = 1, options = {})
  write(:increment, key, amount, options)
  read
end
key?(key, options = {}) click to toggle source

(see Moneta::Proxy#key?)

# File lib/moneta/adapters/client.rb, line 20
def key?(key, options = {})
  write(:key?, key, options)
  read
end
load(key, options = {}) click to toggle source

(see Moneta::Proxy#load)

# File lib/moneta/adapters/client.rb, line 26
def load(key, options = {})
  write(:load, key, options)
  read
end
store(key, value, options = {}) click to toggle source

(see Moneta::Proxy#store)

# File lib/moneta/adapters/client.rb, line 32
def store(key, value, options = {})
  write(:store, key, value, options)
  read
  value
end

Private Instance Methods

read() click to toggle source
# File lib/moneta/adapters/client.rb, line 85
def read
  size = @socket.read(4).unpack('N').first
  result = Marshal.load(@socket.read(size))
  raise result if Exception === result
  result
end
write(*args) click to toggle source
# File lib/moneta/adapters/client.rb, line 80
def write(*args)
  s = Marshal.dump(args)
  @socket.write([s.bytesize].pack('N') << s)
end