lib/redis/value.rb in redis-objects-0.5.2 vs lib/redis/value.rb in redis-objects-0.5.3

- old
+ new

@@ -11,23 +11,36 @@ include Redis::Helpers::Serialize attr_reader :key, :options, :redis def initialize(key, *args) super(key, *args) - @redis.setnx(key, @options[:default]) if @options[:default] + @redis.setnx(key, to_redis(@options[:default])) if @options[:default] end def value=(val) - redis.set key, to_redis(val) + if val.nil? + delete + else + redis.set key, to_redis(val) + end end alias_method :set, :value= def value from_redis redis.get(key) end alias_method :get, :value - def to_s; value.to_s; end - def ==(x); value == x; end - def nil?; value.nil?; end + def inspect + "#<Redis::Value #{value.inspect}>" + end + + def ==(other); value == other end + def nil?; value.nil? end + def as_json(*args); value.as_json *args end + def to_json(*args); value.to_json *args end + + def method_missing(*args) + self.value.send *args + end end end