redistat 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/redistat.rb +2 -0
- data/lib/redistat/connection.rb +3 -6
- data/lib/redistat/date.rb +0 -7
- data/lib/redistat/date_helper.rb +8 -0
- data/lib/redistat/version.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/thread_safety_spec.rb +39 -0
- metadata +15 -3
data/Gemfile.lock
CHANGED
data/lib/redistat.rb
CHANGED
@@ -13,6 +13,7 @@ require 'redistat/collection'
|
|
13
13
|
require 'redistat/connection'
|
14
14
|
require 'redistat/database'
|
15
15
|
require 'redistat/date'
|
16
|
+
require 'redistat/date_helper'
|
16
17
|
require 'redistat/event'
|
17
18
|
require 'redistat/finder'
|
18
19
|
require 'redistat/finder/date_set'
|
@@ -22,6 +23,7 @@ require 'redistat/model'
|
|
22
23
|
require 'redistat/result'
|
23
24
|
require 'redistat/scope'
|
24
25
|
require 'redistat/summary'
|
26
|
+
require 'redistat/version'
|
25
27
|
|
26
28
|
require 'redistat/core_ext/date'
|
27
29
|
require 'redistat/core_ext/time'
|
data/lib/redistat/connection.rb
CHANGED
@@ -18,6 +18,7 @@ module Redistat
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def create(options = {})
|
21
|
+
#TODO clean/remove all ref-less connections
|
21
22
|
ref = options.delete(:ref) || :default
|
22
23
|
options.reverse_merge!(default_options)
|
23
24
|
conn = (connections[connection_id(options)] ||= connection(options))
|
@@ -26,15 +27,11 @@ module Redistat
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def connections
|
29
|
-
|
30
|
+
@connections ||= {}
|
30
31
|
end
|
31
32
|
|
32
33
|
def references
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def threaded
|
37
|
-
Thread.current[:redistat] ||= {}
|
34
|
+
@references ||= {}
|
38
35
|
end
|
39
36
|
|
40
37
|
private
|
data/lib/redistat/date.rb
CHANGED
data/lib/redistat/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Redistat
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
2
|
+
VERSION = "0.0.8"
|
3
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Thread-Safety" do
|
4
|
+
include Redistat::Database
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
db.flushdb
|
8
|
+
end
|
9
|
+
|
10
|
+
#TODO should have more comprehensive thread-safe tests
|
11
|
+
|
12
|
+
it "should incr in multiple threads" do
|
13
|
+
threads = []
|
14
|
+
50.times do
|
15
|
+
threads << Thread.new {
|
16
|
+
db.incr("spec:incr")
|
17
|
+
}
|
18
|
+
end
|
19
|
+
threads.each { |t| t.join }
|
20
|
+
db.get("spec:incr").should == "50"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should store event in multiple threads" do
|
24
|
+
class ThreadSafetySpec
|
25
|
+
include Redistat::Model
|
26
|
+
end
|
27
|
+
threads = []
|
28
|
+
50.times do
|
29
|
+
threads << Thread.new {
|
30
|
+
ThreadSafetySpec.store("spec:threadsafe", {:count => 1, :rand => rand(5)})
|
31
|
+
}
|
32
|
+
end
|
33
|
+
threads.each { |t| t.join }
|
34
|
+
result = ThreadSafetySpec.fetch("spec:threadsafe", 5.hours.ago, 5.hours.from_now)
|
35
|
+
result.total[:count].should == 50
|
36
|
+
result.total[:rand].should <= 250
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redistat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jim Myhrberg
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2011-01-12 00:00:00 +00:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
28
30
|
segments:
|
29
31
|
- 2
|
30
32
|
- 3
|
@@ -40,6 +42,7 @@ dependencies:
|
|
40
42
|
requirements:
|
41
43
|
- - ">="
|
42
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 7
|
43
46
|
segments:
|
44
47
|
- 1
|
45
48
|
- 4
|
@@ -55,6 +58,7 @@ dependencies:
|
|
55
58
|
requirements:
|
56
59
|
- - ">="
|
57
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 11
|
58
62
|
segments:
|
59
63
|
- 2
|
60
64
|
- 1
|
@@ -70,6 +74,7 @@ dependencies:
|
|
70
74
|
requirements:
|
71
75
|
- - ">="
|
72
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 7
|
73
78
|
segments:
|
74
79
|
- 0
|
75
80
|
- 2
|
@@ -85,6 +90,7 @@ dependencies:
|
|
85
90
|
requirements:
|
86
91
|
- - ">="
|
87
92
|
- !ruby/object:Gem::Version
|
93
|
+
hash: 11
|
88
94
|
segments:
|
89
95
|
- 2
|
90
96
|
- 1
|
@@ -100,6 +106,7 @@ dependencies:
|
|
100
106
|
requirements:
|
101
107
|
- - ">="
|
102
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 1
|
103
110
|
segments:
|
104
111
|
- 0
|
105
112
|
- 6
|
@@ -134,6 +141,7 @@ files:
|
|
134
141
|
- lib/redistat/core_ext/time.rb
|
135
142
|
- lib/redistat/database.rb
|
136
143
|
- lib/redistat/date.rb
|
144
|
+
- lib/redistat/date_helper.rb
|
137
145
|
- lib/redistat/event.rb
|
138
146
|
- lib/redistat/finder.rb
|
139
147
|
- lib/redistat/finder/date_set.rb
|
@@ -162,6 +170,7 @@ files:
|
|
162
170
|
- spec/scope_spec.rb
|
163
171
|
- spec/spec_helper.rb
|
164
172
|
- spec/summary_spec.rb
|
173
|
+
- spec/thread_safety_spec.rb
|
165
174
|
has_rdoc: true
|
166
175
|
homepage: http://github.com/jimeh/redistat
|
167
176
|
licenses: []
|
@@ -176,6 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
185
|
requirements:
|
177
186
|
- - ">="
|
178
187
|
- !ruby/object:Gem::Version
|
188
|
+
hash: 3
|
179
189
|
segments:
|
180
190
|
- 0
|
181
191
|
version: "0"
|
@@ -184,6 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
194
|
requirements:
|
185
195
|
- - ">="
|
186
196
|
- !ruby/object:Gem::Version
|
197
|
+
hash: 3
|
187
198
|
segments:
|
188
199
|
- 0
|
189
200
|
version: "0"
|
@@ -212,3 +223,4 @@ test_files:
|
|
212
223
|
- spec/scope_spec.rb
|
213
224
|
- spec/spec_helper.rb
|
214
225
|
- spec/summary_spec.rb
|
226
|
+
- spec/thread_safety_spec.rb
|