Class | Familia::RedisObject |
In: |
lib/familia/redisobject.rb
|
Parent: | Object |
cache | [R] | RedisObject instances are frozen. `cache` is a hash for you to store values retreived from Redis. This is not used anywhere by default, but you‘re encouraged to use it in your specific scenarios. |
classes | [W] | |
db | [W] | |
name | [R] | |
parent | [R] | |
parent | [RW] | |
redis | [W] | |
ttl | [W] | |
uri | [W] |
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[:extend]".
: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[:redis] or Familia.redis (in that order).
To be called inside every class that inherits RedisObject meth becomes the base for the class and instances methods that are created for the given klass (e.g. Obj.list)
Returns the most likely value for db, checking (in this order):
* the value from :class if it's a Familia object * the value from :parent * the value self.class.db * assumes the db is 0
After this is called once, this method will always return the same value.