Module: Dalli::Client::MemcacheClientCompatibility

Defined in:
lib/dalli/compatibility.rb

Instance Method Summary collapse

Instance Method Details

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



19
20
21
22
23
24
25
# File 'lib/dalli/compatibility.rb', line 19

def add(key, value, ttl = nil, options = nil)
  if options == true || options == false
    Dalli.logger.error("Dalli: please use add(key, value, ttl, :raw => boolean): #{caller[0]}")
    options = { :raw => options }
  end
  super(key, value, ttl, options) ? "STORED\r\n" : "NOT_STORED\r\n"
end

#delete(key) ⇒ Object



47
48
49
# File 'lib/dalli/compatibility.rb', line 47

def delete(key)
  super(key) ? "DELETED\r\n" : "NOT_DELETED\r\n"
end

#get(key, options = nil) ⇒ Object

Dalli does not unmarshall data that does not have the marshalled flag set so we need to unmarshall manually any marshalled data originally put in memcached by memcache-client. Peek at the data and see if it looks marshalled.



38
39
40
41
42
43
44
45
# File 'lib/dalli/compatibility.rb', line 38

def get(key, options = nil)
  value = super(key, options)
  if value && value.is_a?(String) && !options && value.size > 2 &&
          bytes = value.unpack('cc') && bytes[0] == 4 && bytes[1] == 8
    return Marshal.load(value) rescue value
  end
  value
end

#initialize(*args) ⇒ Object



5
6
7
8
# File 'lib/dalli/compatibility.rb', line 5

def initialize(*args)
  Dalli.logger.error("Starting Dalli in memcache-client compatibility mode")
  super(*args)
end

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



27
28
29
30
31
32
33
# File 'lib/dalli/compatibility.rb', line 27

def replace(key, value, ttl = nil, options = nil)
  if options == true || options == false
    Dalli.logger.error("Dalli: please use replace(key, value, ttl, :raw => boolean): #{caller[0]}")
    options = { :raw => options }
  end
  super(key, value, ttl, options) ? "STORED\r\n" : "NOT_STORED\r\n"
end

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



10
11
12
13
14
15
16
17
# File 'lib/dalli/compatibility.rb', line 10

def set(key, value, ttl = nil, options = nil)
  if options == true || options == false
    Dalli.logger.error("Dalli: please use set(key, value, ttl, :raw => boolean): #{caller[0]}")
    options = { :raw => options }
  end
  super(key, value, ttl, options) ? "STORED\r\n" : "NOT_STORED\r\n"

end