Sha256: df4b5b23f878d18e319b97a604ba6d63b21175a6d060e3d8f09f8f0ec816463c

Contents?: true

Size: 905 Bytes

Versions: 4

Compression:

Stored size: 905 Bytes

Contents

require File.dirname(__FILE__) + '/base_object'

class Redis
  #
  # Class representing a simple value.  You can use standard Ruby operations on it.
  #
  class Value < BaseObject
    require 'redis/helpers/core_commands'
    include Redis::Helpers::CoreCommands

    attr_reader :key, :options

    def value=(val)
      allow_expiration do
        if val.nil?
          delete
        else
          redis.set key, marshal(val)
        end
      end
    end
    alias_method :set, :value=

    def value
      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 method_missing(*args)
      self.value.send *args
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
redis-objects-1.4.2 lib/redis/value.rb
redis-objects-1.4.0 lib/redis/value.rb
redis-objects-1.3.1 lib/redis/value.rb
redis-objects-1.3.0 lib/redis/value.rb