Class: Memcache::Base

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

Direct Known Subclasses

LocalServer, NativeServer, NullServer, PGServer, Server

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) prefix

Returns the value of attribute prefix



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

def prefix
  @prefix
end

Instance Method Details

- (Object) add(key, value, expiry = 0, flags = 0)



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

- (Object) append(key, value)



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

- (Object) cas(key, value, cas, expiry = 0, flags = 0)



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

- (Object) clear



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

def clear
  flush_all
end

- (Object) decr(key, amount = 1)



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

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

- (Object) gets(keys)

Default implementations based on get and set.



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

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

- (Object) incr(key, amount = 1)



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

- (Object) prepend(key, value)



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

- (Object) replace(key, value, expiry = 0, flags = 0)



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