Class: MemcachePod::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/memcachepod/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(servers = nil, options = {}) ⇒ Client

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.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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

Instance Method Details

#add(key, value, ttl = nil, options = nil) ⇒ Object

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/memcachepod/client.rb', line 50

def add(key, value, ttl=nil, options=nil)
  raise NotImplementedError.new("not implemented add()")
end

#alive!Object

Raises:

  • (NotImplementedError)


90
91
92
# File 'lib/memcachepod/client.rb', line 90

def alive!
  raise NotImplementedError.new("not implemented alive!()")      
end

#append(key, value) ⇒ Object

Raises:

  • (NotImplementedError)


62
63
64
# 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) ⇒ Object

Raises:

  • (NotImplementedError)


74
75
76
# 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) ⇒ Object



58
59
60
# File 'lib/memcachepod/client.rb', line 58

def delete(key)
  @memory.delete(key)
end

#flush(delay = 0) ⇒ Object Also known as: flush_all



98
99
100
# File 'lib/memcachepod/client.rb', line 98

def flush(delay=0)
  @memory.flush()
end

#get(key, options = nil) ⇒ Object



39
40
41
42
# File 'lib/memcachepod/client.rb', line 39

def get(key, options=nil)
  key = validate_key(key)
  return @memory.get(key, options)
end

#get_memory_usageObject



112
113
114
# File 'lib/memcachepod/client.rb', line 112

def get_memory_usage
  return @memory.get_memory_usage
end

#get_optionsObject



108
109
110
# File 'lib/memcachepod/client.rb', line 108

def get_options
  return @options
end

#get_statusObject



102
103
104
# File 'lib/memcachepod/client.rb', line 102

def get_status
  return @memory.get_status
end

#incr(key, amt = 1, ttl = nil, default = nil) ⇒ Object

Raises:

  • (NotImplementedError)


70
71
72
# 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) ⇒ Object

Raises:

  • (NotImplementedError)


66
67
68
# 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) ⇒ Object

Raises:

  • (NotImplementedError)


54
55
56
# File 'lib/memcachepod/client.rb', line 54

def replace(key, value, ttl=nil, options=nil)
  raise NotImplementedError.new("not implemented replace()")
end

#reset_statsObject

Raises:

  • (NotImplementedError)


86
87
88
# 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) ⇒ Object



44
45
46
47
48
# 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) ⇒ Object

Raises:

  • (NotImplementedError)


82
83
84
# File 'lib/memcachepod/client.rb', line 82

def stats(type=nil)
  raise NotImplementedError.new("not implemented stats()")
end

#touch(key, ttl = nil) ⇒ Object

Raises:

  • (NotImplementedError)


78
79
80
# File 'lib/memcachepod/client.rb', line 78

def touch(key, ttl=nil)
  raise NotImplementedError.new("not implemented touch()")
end

#versionObject



94
95
96
# File 'lib/memcachepod/client.rb', line 94

def version
  { "localhost" => MemcachePod::VERSION }
end