lib/redis/value.rb in redis-objects-1.4.2 vs lib/redis/value.rb in redis-objects-1.4.3

- old
+ new

@@ -1,6 +1,7 @@ require File.dirname(__FILE__) + '/base_object' +require 'zlib' class Redis # # Class representing a simple value. You can use standard Ruby operations on it. # @@ -28,9 +29,33 @@ else value end end alias_method :get, :value + + def marshal(value, *args) + if !value.nil? && options[:compress] + compress(super) + else + super + end + end + + def unmarshal(value, *args) + if !value.nil? && options[:compress] + super(decompress(value), *args) + else + super + end + end + + def decompress(value) + Zlib::Inflate.inflate(value) + end + + def compress(value) + Zlib::Deflate.deflate(value) + end def inspect "#<Redis::Value #{value.inspect}>" end