lib/redis/value.rb in redis-objects-0.2.0 vs lib/redis/value.rb in redis-objects-0.2.1

- old
+ new

@@ -1,33 +1,31 @@ class Redis # # Class representing a simple value. You can use standard Ruby operations on it. # class Value + require 'redis/serialize' + include Redis::Serialize + attr_reader :key, :options, :redis def initialize(key, redis=$redis, options={}) @key = key @redis = redis @options = options @redis.setnx(key, @options[:default]) if @options[:default] end - def value - @value ||= get - end - def value=(val) - redis.set(key, val) - @value = val + redis.set(key, to_redis(val)) end - def get - @value = redis.get(key) + def value + from_redis redis.get(key) end - + alias_method :get, :value + def delete redis.del(key) - @value = nil end alias_method :del, :delete def to_s; value.to_s; end alias_method :to_str, :to_s \ No newline at end of file