forked from petergoldstein/dalli
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bug-fix_memcache_compatibility'
- Loading branch information
Showing
6 changed files
with
78 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.bundle | ||
.idea | ||
Gemfile.lock | ||
tmtags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1 @@ | ||
require 'dalli/client' | ||
|
||
class Dalli::Client | ||
module MemcacheClientCompatibility | ||
|
||
def initialize(*args) | ||
Dalli.logger.error("Starting Dalli in memcache-client compatibility mode") | ||
super(*args) | ||
end | ||
|
||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
# 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. | ||
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 | ||
|
||
def delete(key) | ||
super(key) ? "DELETED\r\n" : "NOT_DELETED\r\n" | ||
end | ||
end | ||
|
||
include MemcacheClientCompatibility unless $TESTING | ||
end | ||
Dalli::Client.compatibility_mode = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class Dalli::Client | ||
|
||
module MemcacheClientCompatibility | ||
|
||
def initialize(*args) | ||
Dalli.logger.error("Starting Dalli in memcache-client compatibility mode") | ||
super(*args) | ||
end | ||
|
||
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 | ||
|
||
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 | ||
|
||
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 | ||
|
||
# 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. | ||
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 | ||
|
||
def delete(key) | ||
super(key) ? "DELETED\r\n" : "NOT_DELETED\r\n" | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters