Class: Cash::Mock

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/cash/mock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#serversObject

Returns the value of attribute servers.



3
4
5
# File 'lib/cash/mock.rb', line 3

def servers
  @servers
end

Instance Method Details

#add(key, value, ttl = 0, raw = false) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/cash/mock.rb', line 39

def add(key, value, ttl = 0, raw = false)
  if self.has_key?(key)
    "NOT_STORED\r\n"
  else
    self[key] = marshal(value, raw)
    "STORED\r\n"
  end
end

#append(key, value) ⇒ Object



48
49
50
# File 'lib/cash/mock.rb', line 48

def append(key, value)
  set(key, get(key, true).to_s + value.to_s, nil, true)
end

#decr(key, amount = 1) ⇒ Object



32
33
34
35
36
37
# File 'lib/cash/mock.rb', line 32

def decr(key, amount = 1)
  if self.has_key?(key)
    self[key] = (self[key].to_i - amount).to_s
    self[key].to_i
  end
end

#flush_allObject



56
57
58
# File 'lib/cash/mock.rb', line 56

def flush_all
  clear
end

#get(key, raw = false) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/cash/mock.rb', line 13

def get(key, raw = false)
  if raw
    self[key]
  else
    if self.has_key?(key)
      Marshal.load(self[key])
    else
      nil
    end
  end
end

#get_multi(keys) ⇒ Object



5
6
7
# File 'lib/cash/mock.rb', line 5

def get_multi(keys)
  slice(*keys).collect { |k,v| [k, Marshal.load(v)] }.to_hash
end

#incr(key, amount = 1) ⇒ Object



25
26
27
28
29
30
# File 'lib/cash/mock.rb', line 25

def incr(key, amount = 1)
  if self.has_key?(key)
    self[key] = (self[key].to_i + amount).to_s
    self[key].to_i
  end
end

#namespaceObject



52
53
54
# File 'lib/cash/mock.rb', line 52

def namespace
  nil
end

#reset_runtimeObject



64
65
66
# File 'lib/cash/mock.rb', line 64

def reset_runtime
  [0, Hash.new(0)]
end

#set(key, value, ttl = 0, raw = false) ⇒ Object



9
10
11
# File 'lib/cash/mock.rb', line 9

def set(key, value, ttl = 0, raw = false)
  self[key] = marshal(value, raw)
end

#statsObject



60
61
62
# File 'lib/cash/mock.rb', line 60

def stats
  {}
end