mirror of
https://github.com/jimeh/redistat.git
synced 2026-02-19 13:26:39 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3267ee1eb9 | |||
| 6309e4b217 | |||
| 776ee8ac97 | |||
| 3b346e88e0 | |||
| c3fe861b10 | |||
| bc5034b6bb |
@@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
redistat (0.0.6)
|
redistat (0.0.8)
|
||||||
activesupport (>= 2.3.0)
|
activesupport (>= 2.3.0)
|
||||||
json (>= 1.4.0)
|
json (>= 1.4.0)
|
||||||
redis (>= 2.1.0)
|
redis (>= 2.1.0)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ require 'redistat/collection'
|
|||||||
require 'redistat/connection'
|
require 'redistat/connection'
|
||||||
require 'redistat/database'
|
require 'redistat/database'
|
||||||
require 'redistat/date'
|
require 'redistat/date'
|
||||||
|
require 'redistat/date_helper'
|
||||||
require 'redistat/event'
|
require 'redistat/event'
|
||||||
require 'redistat/finder'
|
require 'redistat/finder'
|
||||||
require 'redistat/finder/date_set'
|
require 'redistat/finder/date_set'
|
||||||
@@ -22,6 +23,7 @@ require 'redistat/model'
|
|||||||
require 'redistat/result'
|
require 'redistat/result'
|
||||||
require 'redistat/scope'
|
require 'redistat/scope'
|
||||||
require 'redistat/summary'
|
require 'redistat/summary'
|
||||||
|
require 'redistat/version'
|
||||||
|
|
||||||
require 'redistat/core_ext/date'
|
require 'redistat/core_ext/date'
|
||||||
require 'redistat/core_ext/time'
|
require 'redistat/core_ext/time'
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ module Redistat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create(options = {})
|
def create(options = {})
|
||||||
|
#TODO clean/remove all ref-less connections
|
||||||
ref = options.delete(:ref) || :default
|
ref = options.delete(:ref) || :default
|
||||||
options.reverse_merge!(default_options)
|
options.reverse_merge!(default_options)
|
||||||
conn = (connections[connection_id(options)] ||= connection(options))
|
conn = (connections[connection_id(options)] ||= connection(options))
|
||||||
@@ -26,15 +27,11 @@ module Redistat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def connections
|
def connections
|
||||||
threaded[:connections] ||= {}
|
@connections ||= {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def references
|
def references
|
||||||
threaded[:references] ||= {}
|
@references ||= {}
|
||||||
end
|
|
||||||
|
|
||||||
def threaded
|
|
||||||
Thread.current[:redistat] ||= {}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -85,11 +85,4 @@ module Redistat
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module DateHelper
|
|
||||||
def to_redistat(depth = nil)
|
|
||||||
Redistat::Date.new(self, depth)
|
|
||||||
end
|
|
||||||
alias :to_rs :to_redistat
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
8
lib/redistat/date_helper.rb
Normal file
8
lib/redistat/date_helper.rb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
module Redistat
|
||||||
|
module DateHelper
|
||||||
|
def to_redistat(depth = nil)
|
||||||
|
Redistat::Date.new(self, depth)
|
||||||
|
end
|
||||||
|
alias :to_rs :to_redistat
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
module Redistat
|
module Redistat
|
||||||
VERSION = "0.0.7"
|
VERSION = "0.0.8"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,5 +8,5 @@ require 'rspec'
|
|||||||
require 'rspec/autorun'
|
require 'rspec/autorun'
|
||||||
|
|
||||||
# use the test Redistat instance
|
# use the test Redistat instance
|
||||||
Redistat.connect(:port => 8379, :db => 15)
|
Redistat.connect(:port => 8379, :db => 15, :thread_safe => true)
|
||||||
Redistat.redis.flushdb
|
Redistat.redis.flushdb
|
||||||
|
|||||||
39
spec/thread_safety_spec.rb
Normal file
39
spec/thread_safety_spec.rb
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe "Thread-Safety" do
|
||||||
|
include Redistat::Database
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
db.flushdb
|
||||||
|
end
|
||||||
|
|
||||||
|
#TODO should have more comprehensive thread-safe tests
|
||||||
|
|
||||||
|
it "should incr in multiple threads" do
|
||||||
|
threads = []
|
||||||
|
50.times do
|
||||||
|
threads << Thread.new {
|
||||||
|
db.incr("spec:incr")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
threads.each { |t| t.join }
|
||||||
|
db.get("spec:incr").should == "50"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should store event in multiple threads" do
|
||||||
|
class ThreadSafetySpec
|
||||||
|
include Redistat::Model
|
||||||
|
end
|
||||||
|
threads = []
|
||||||
|
50.times do
|
||||||
|
threads << Thread.new {
|
||||||
|
ThreadSafetySpec.store("spec:threadsafe", {:count => 1, :rand => rand(5)})
|
||||||
|
}
|
||||||
|
end
|
||||||
|
threads.each { |t| t.join }
|
||||||
|
result = ThreadSafetySpec.fetch("spec:threadsafe", 5.hours.ago, 5.hours.from_now)
|
||||||
|
result.total[:count].should == 50
|
||||||
|
result.total[:rand].should <= 250
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user