Skip to content

Commit

Permalink
FIXED: Clone options for each RedisObject instance to prevent cross c…
Browse files Browse the repository at this point in the history
…ontamination.
  • Loading branch information
delano committed Apr 10, 2011
1 parent 14fd10e commit 2654a7a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -5,6 +5,7 @@ FAMILIA, CHANGES

* FIXED: Explicitly convert boolean conf options to true or false. Redis client
treats "true" as false.
* FIXED: Clone options for each RedisObject instance to prevent cross contamination.
* CHANGE: Fix for Familia objects with custom suffixes
* CHANGE: Familia::String methods that modify the key now automatically update_expiration.
* ADDED: Familia.qnow, Familia::Object.qstamp, RedisObject#qstamp
Expand Down
8 changes: 4 additions & 4 deletions lib/familia/object.rb
Expand Up @@ -109,8 +109,8 @@ def qstamp quantum=nil, pattern=nil, now=Familia.now
def install_class_redis_object name, klass, opts
raise ArgumentError, "Name is blank" if name.to_s.empty?
name = name.to_s.to_sym
opts ||= {}
opts[:parent] ||= self
opts = opts.nil? ? {} : opts.clone
opts[:parent] = self unless opts.has_key?(:parent)
# TODO: investigate using metaclass.redis_objects
class_redis_objects_order << name
class_redis_objects[name] = OpenStruct.new
Expand Down Expand Up @@ -334,8 +334,8 @@ def initialize_redis_objects
# See RedisObject.install_redis_object
self.class.redis_objects.each_pair do |name, redis_object_definition|
klass, opts = redis_object_definition.klass, redis_object_definition.opts
opts ||= {}
opts[:parent] ||= self
opts = opts.nil? ? {} : opts.clone
opts[:parent] = self unless opts.has_key?(:parent)
redis_object = klass.new name, opts
redis_object.freeze
self.instance_variable_set "@#{name}", redis_object
Expand Down
7 changes: 1 addition & 6 deletions try/10_familia_try.rb
Expand Up @@ -50,9 +50,4 @@
## Familia::Object#qstamp
limiter = Limiter.new :request
limiter.qstamp 10.minutes, '%H:%M', 1302468980
#=> '20:50'

## Familia::Object#qstamp
limiter = Limiter.new :request
limiter.qstamp 10.minutes, '%H:%M', 1302468980
#=> '20:50'
##=> '20:50'
14 changes: 10 additions & 4 deletions try/20_redis_object_try.rb
Expand Up @@ -5,8 +5,8 @@


## Redis Objects are unique per instance of a Familia class
@a = Bone.new 'atoken'
@b = Bone.new 'btoken'
@a = Bone.new 'atoken', :name1
@b = Bone.new 'atoken', :name2
@a.owners.rediskey == @b.owners.rediskey
#=> false

Expand All @@ -33,7 +33,13 @@
@limiter.counter.ttl
#=> 3600

## Check ttl for a different instance
## (this exists to make sure options are cloned for each instance)
@limiter2 = Limiter.new :requests
@limiter2.counter.ttl
#=> 3600

## Check realttl
sleep 2
sleep 1
@limiter.counter.realttl
#=> 3600-2
#=> 3600-1

0 comments on commit 2654a7a

Please sign in to comment.