Skip to content

Commit

Permalink
Resolved issues introduced by switching the incr and decr methods to …
Browse files Browse the repository at this point in the history
…using raw numbers.
  • Loading branch information
fredjean committed Sep 6, 2010
1 parent d116d6e commit a5bc402
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/memcache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,17 @@ def get(key, raw = false)
value = @client.get(make_cache_key(key))
return nil if value.nil?
unless raw
marshal_bytes = java.lang.String.new(value).getBytes(MARSHALLING_CHARSET)
decoded = Base64.decode64(String.from_java_bytes(marshal_bytes))
value = Marshal.load(decoded)
begin
marshal_bytes = java.lang.String.new(value).getBytes(MARSHALLING_CHARSET)
decoded = Base64.decode64(String.from_java_bytes(marshal_bytes))
value = Marshal.load(decoded)
rescue
value = case value
when /^\d+\.\d+$/ then value.to_f
when /^\d+$/ then value.to_i
else value
end
end
end
value
end
Expand All @@ -200,9 +208,17 @@ def get_multi(keys, raw = false)
k,v = kv
next if v.nil?
unless raw
marshal_bytes = java.lang.String.new(v).getBytes(MARSHALLING_CHARSET)
decoded = Base64.decode64(String.from_java_bytes(marshal_bytes))
v = Marshal.load(decoded)
begin
marshal_bytes = java.lang.String.new(v).getBytes(MARSHALLING_CHARSET)
decoded = Base64.decode64(String.from_java_bytes(marshal_bytes))
v = Marshal.load(decoded)
rescue
v = case v
when /^\d+\.\d+$/ then v.to_f
when /^\d+$/ then v.to_i
else v
end
end
end
values[k] = v
}
Expand Down Expand Up @@ -320,6 +336,7 @@ def expiration(expiry)
end

def marshal_value(value)
return value if value.kind_of?(Numeric)
encoded = Base64.encode64(Marshal.dump(value))
marshal_bytes = encoded.to_java_bytes
java.lang.String.new(marshal_bytes, MARSHALLING_CHARSET)
Expand Down

0 comments on commit a5bc402

Please sign in to comment.