Created
December 17, 2011 01:27
-
-
Save anonymous/1488796 to your computer and use it in GitHub Desktop.
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
--- /usr/local/rvm/gems/ree-1.8.7-2010.02/gems/memcache-client-1.5.0/lib/memcache.rb.orig 2011-12-16 14:44:29.806155993 -0800 | |
+++ /usr/local/rvm/gems/ree-1.8.7-2010.02/gems/memcache-client-1.5.0/lib/memcache.rb 2011-12-16 16:51:26.468961991 -0800 | |
@@ -4,6 +4,7 @@ | |
require 'thread' | |
require 'timeout' | |
require 'rubygems' | |
+require 'base64' | |
class String | |
@@ -211,7 +212,7 @@ | |
return nil if value.nil? | |
- value = Marshal.load value unless raw | |
+ value = adaptive_unmarshal(value) unless raw | |
return value | |
rescue TypeError, SocketError, SystemCallError, IOError => err | |
@@ -259,7 +260,7 @@ | |
cache_get_multi server, keys | |
end | |
values.each do |key, value| | |
- results[cache_keys[key]] = Marshal.load value | |
+ results[cache_keys[key]] = adaptive_unmarshal(value) | |
end | |
end | |
@@ -801,5 +802,21 @@ | |
class MemCacheError < RuntimeError; end | |
+ private | |
+ | |
+ def adaptive_unmarshal(data) | |
+ Marshal.load( | |
+ # Look at the first two bytes to see if it's been base64-encoded | |
+ case [data[0], data[1]] | |
+ when [4,8] | |
+ data | |
+ when [66,65] | |
+ Base64.decode64(data) | |
+ else | |
+ throw "Unrecognized data format pulled from memcache: " + data | |
+ 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
--- /usr/local/rvm/gems/ree-1.8.7-2010.02/gems/memcache-client-1.5.0/lib/memcache.rb.orig 2011-12-16 16:56:28.398137005 -0800 | |
+++ /usr/local/rvm/gems/ree-1.8.7-2010.02/gems/memcache-client-1.5.0/lib/memcache.rb 2011-12-16 17:20:32.235578001 -0800 | |
@@ -298,7 +298,7 @@ | |
server, cache_key = request_setup key | |
socket = server.socket | |
- value = Marshal.dump value unless raw | |
+ value = Base64.encode64(Marshal.dump(value)) unless raw | |
command = "set #{cache_key} 0 #{expiry} #{value.size}\r\n#{value}\r\n" | |
begin | |
@@ -327,7 +327,7 @@ | |
server, cache_key = request_setup key | |
socket = server.socket | |
- value = Marshal.dump value unless raw | |
+ value = Base64.encode64(Marshal.dump(value)) unless raw | |
command = "add #{cache_key} 0 #{expiry} #{value.size}\r\n#{value}\r\n" | |
begin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment