Class: Memcache::Base

Inherits:
Object show all
Defined in:
lib/memcache/base.rb,
ext/native_server.c

Direct Known Subclasses

LocalServer, NativeServer, NullServer, PGServer, Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#prefixObject

Returns the value of attribute prefix.



3
4
5
# File 'lib/memcache/base.rb', line 3

def prefix
  @prefix
end

Instance Method Details

#add(key, value, expiry = 0, flags = 0) ⇒ Object



30
31
32
33
# File 'lib/memcache/base.rb', line 30

def add(key, value, expiry = 0, flags = 0)
  return nil if get(key)
  set(key, value, expiry)
end

#append(key, value) ⇒ Object



45
46
47
48
49
# File 'lib/memcache/base.rb', line 45

def append(key, value)
  existing = get(key)
  return false if existing.nil?
  set(key, existing + value) && true
end

#cas(key, value, cas, expiry = 0, flags = 0) ⇒ Object



35
36
37
38
# File 'lib/memcache/base.rb', line 35

def cas(key, value, cas, expiry = 0, flags = 0)
  # No cas implementation yet, just do a set for now.
  set(key, value, expiry, flags)
end

#clearObject



5
6
7
# File 'lib/memcache/base.rb', line 5

def clear
  flush_all
end

#decr(key, amount = 1) ⇒ Object



26
27
28
# File 'lib/memcache/base.rb', line 26

def decr(key, amount = 1)
  incr(key, -amount)
end

#gets(keys) ⇒ Object

Default implementations based on get and set.



11
12
13
# File 'lib/memcache/base.rb', line 11

def gets(keys)
  get(keys, true)
end

#incr(key, amount = 1) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/memcache/base.rb', line 15

def incr(key, amount = 1)
  value = get(key)
  return unless value
  return unless value =~ /^\d+$/

  value = value.to_i + amount
  value = 0 if value < 0
  set(key, value.to_s)
  value
end

#prepend(key, value) ⇒ Object



51
52
53
54
55
# File 'lib/memcache/base.rb', line 51

def prepend(key, value)
  existing = get(key)
  return false if existing.nil?
  set(key, value + existing) && true
end

#replace(key, value, expiry = 0, flags = 0) ⇒ Object



40
41
42
43
# File 'lib/memcache/base.rb', line 40

def replace(key, value, expiry = 0, flags = 0)
  return nil if get(key).nil?
  set(key, value, expiry)
end