class MemcachePod::Client

Public Class Methods

new(servers=nil, options={}) click to toggle source

MemcachePod::Client is the main class which developers will use to interact with.

MemcachePod::Client.new(['localhost:11211:10', 'cache-2:11211:5']

,threadsafe => true, :expires_in => 300)

This class aims to keep compatiblity ather memcache client.

# File lib/memcachepod/client.rb, line 15
def initialize(servers=nil, options={})
  @options = Hash.new

  @options[:expires_in] = 0
  @options[:threadsafe] = true
  @options[:namespace]  = ''
  @options[:max_memory]  = 64*1024*1024 # same as memcached
  
  if options.has_key?(:expires_in)
    @options[:expires_in] = options[:expires_in]
  end
  if options.has_key?(:threadsafe)
    @options[:threadsafe] = options[:threadsafe]
  end
  if options.has_key?(:namespace)
    @options[:namespace]  = options[:namespace]
  end
  if options.has_key?(:max_memory)
    @options[:max_memory]  = options[:max_memory]
  end

  @memory = Memory.new(@options[:max_memory])
end

Public Instance Methods

add(key, value, ttl=nil, options=nil) click to toggle source
# File lib/memcachepod/client.rb, line 50
def add(key, value, ttl=nil, options=nil)
  raise NotImplementedError.new("not implemented add()")
end
alive!() click to toggle source
# File lib/memcachepod/client.rb, line 90
def alive!
  raise NotImplementedError.new("not implemented alive!()")      
end
append(key, value) click to toggle source
# File lib/memcachepod/client.rb, line 62
def append(key, value)
  raise NotImplementedError.new("not implemented append()")
end
decr(key, amt=1, ttl=nil, default=nil) click to toggle source
# File lib/memcachepod/client.rb, line 74
def decr(key, amt=1, ttl=nil, default=nil)
  raise NotImplementedError.new("not implemented decr()")
end
delete(key) click to toggle source
# File lib/memcachepod/client.rb, line 58
def delete(key)
  @memory.delete(key)
end
flush(delay=0) click to toggle source
# File lib/memcachepod/client.rb, line 98
def flush(delay=0)
  @memory.flush()
end
Also aliased as: flush_all
flush_all(delay=0)
Alias for: flush
get(key, options=nil) click to toggle source
# File lib/memcachepod/client.rb, line 39
def get(key, options=nil)
  key = validate_key(key)
  return @memory.get(key, options)
end
get_memory_usage() click to toggle source
# File lib/memcachepod/client.rb, line 112
def get_memory_usage
  return @memory.get_memory_usage
end
get_options() click to toggle source
# File lib/memcachepod/client.rb, line 108
def get_options
  return @options
end
get_status() click to toggle source
# File lib/memcachepod/client.rb, line 102
def get_status
  return @memory.get_status
end
incr(key, amt=1, ttl=nil, default=nil) click to toggle source
# File lib/memcachepod/client.rb, line 70
def incr(key, amt=1, ttl=nil, default=nil)
  raise NotImplementedError.new("not implemented incr()")
end
prepend(key, value) click to toggle source
# File lib/memcachepod/client.rb, line 66
def prepend(key, value)
  raise NotImplementedError.new("not implemented prepend()")
end
replace(key, value, ttl=nil, options=nil) click to toggle source
# File lib/memcachepod/client.rb, line 54
def replace(key, value, ttl=nil, options=nil)
  raise NotImplementedError.new("not implemented replace()")
end
reset_stats() click to toggle source
# File lib/memcachepod/client.rb, line 86
def reset_stats
  raise NotImplementedError.new("not implemented reset_stats()")
end
set(key, value, ttl=nil, options=nil) click to toggle source
# File lib/memcachepod/client.rb, line 44
def set(key, value, ttl=nil, options=nil)
  key = validate_key(key)
  ttl = ttl_or_default(ttl)
  @memory.set(key, value, ttl, options)
end
stats(type=nil) click to toggle source
# File lib/memcachepod/client.rb, line 82
def stats(type=nil)
  raise NotImplementedError.new("not implemented stats()")
end
touch(key, ttl=nil) click to toggle source
# File lib/memcachepod/client.rb, line 78
def touch(key, ttl=nil)
  raise NotImplementedError.new("not implemented touch()")
end
version() click to toggle source
# File lib/memcachepod/client.rb, line 94
def version
  { "localhost" => MemcachePod::VERSION }
end

Private Instance Methods

key_with_namespace(key) click to toggle source
# File lib/memcachepod/client.rb, line 124
def key_with_namespace(key)
  # TODO: implement namespace
  return key
end
ttl_or_default(ttl) click to toggle source
# File lib/memcachepod/client.rb, line 129
def ttl_or_default(ttl)
  if ttl
    ttl
  else
    @options[:expires_in].to_i
  end
end
validate_key(key) click to toggle source
# File lib/memcachepod/client.rb, line 118
def validate_key(key)
  raise ArgumentError, "key cannot be blank" if !key || key.length == 0
  key = key_with_namespace(key)
  return key
end