Method: Familia::RedisObject#initialize
- Defined in:
- lib/familia/redisobject.rb
#initialize(name, opts = {}) ⇒ RedisObject
name
: If parent is set, this will be used as the suffix for rediskey. Otherwise this becomes the value of the key. If this is an Array, the elements will be joined.
Options:
:class => A class that responds to Familia.load_method and Familia.dump_method. These will be used when loading and saving data from/to redis to unmarshal/marshal the class.
:reference => When true the index of the given value will be stored rather than the marshaled value. This assumes that the marshaled object is stored at a separate key. When read, from_redis looks for that separate key and returns the unmarshaled object. :class must be specified. Default: false.
:extend => Extend this instance with the functionality in an other module. Literally: “self.extend opts”.
:parent => The Familia object that this redis object belongs to. This can be a class that includes Familia or an instance.
:ttl => the time to live in seconds. When not nil, this will set the redis expire for this key whenever #save is called. You can also call it explicitly via #update_expiration.
:quantize => append a quantized timestamp to the rediskey. Takes one of the following:
Boolean: include the default stamp (now % 10 minutes)
Integer: the number of seconds to quantize to (e.g. 1.hour)
Array: All arguments for qstamp (quantum, pattern, Time.now)
:default => the default value (String-only)
:dump_method => the instance method to call to serialize the object before sending it to Redis (default: Familia.dump_method).
:load_method => the class method to call to deserialize the object after it’s read from Redis (default: Familia.load_method).
:db => the redis database to use (ignored if :redis is used).
:redis => an instance of Redis.
Uses the redis connection of the parent or the value of opts or Familia.redis (in that order).
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/familia/redisobject.rb', line 104 def initialize name, opts={} @name, @opts = name, opts @name = @name.join(Familia.delim) if Array === @name #Familia.ld [name, opts, caller[0]].inspect self.extend @opts[:extend] if Module === @opts[:extend] @db = @opts.delete(:db) @parent = @opts.delete(:parent) @ttl ||= @opts.delete(:ttl) @redis ||= @opts.delete(:redis) @cache = {} init if respond_to? :init end |