lib/redis/value.rb in redis-objects-1.2.1 vs lib/redis/value.rb in redis-objects-1.3.0

- old
+ new

@@ -7,14 +7,10 @@ class Value < BaseObject require 'redis/helpers/core_commands' include Redis::Helpers::CoreCommands attr_reader :key, :options - def initialize(key, *args) - super(key, *args) - redis.setnx(key, marshal(@options[:default])) if !@options[:default].nil? - end def value=(val) allow_expiration do if val.nil? delete @@ -24,21 +20,24 @@ end end alias_method :set, :value= def value - unmarshal redis.get(key) + value = unmarshal(redis.get(key)) + if value.nil? && !@options[:default].nil? + @options[:default] + else + value + end end alias_method :get, :value 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