Permalink
Browse files

Use Redis increment to update counts

Increment alternative participant and completion
count using atomic Redis operations. Let Redis
handle concurrency.
  • Loading branch information...
lautis committed Sep 26, 2011
1 parent 60443ee commit 1f6e0fd3c97de083fecf1ef4c63acc20b8d5871d
Showing with 6 additions and 2 deletions.
  1. +2 −2 lib/split/alternative.rb
  2. +4 −0 spec/alternative_spec.rb
View
@@ -18,12 +18,12 @@ def to_s
def increment_participation
@participant_count +=1
- self.save
+ Split.redis.hincrby "#{experiment_name}:#{name}", 'participant_count', 1
end
def increment_completion
@completed_count +=1
- self.save
+ Split.redis.hincrby "#{experiment_name}:#{name}", 'completed_count', 1
end
def control?
View
@@ -40,6 +40,8 @@
old_participant_count = alternative.participant_count
alternative.increment_participation
alternative.participant_count.should eql(old_participant_count+1)
+
+ Split::Alternative.find('Basket', 'basket_text').participant_count.should eql(old_participant_count+1)
end
it "should increment completed count" do
@@ -49,6 +51,8 @@
old_completed_count = alternative.participant_count
alternative.increment_completion
alternative.completed_count.should eql(old_completed_count+1)
+
+ Split::Alternative.find('Basket', 'basket_text').completed_count.should eql(old_completed_count+1)
end
it "can be reset" do

0 comments on commit 1f6e0fd

Please sign in to comment.