redistat 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -1
- data/lib/redistat.rb +5 -0
- data/lib/redistat/key.rb +1 -1
- data/lib/redistat/label.rb +4 -4
- data/lib/redistat/summary.rb +2 -2
- data/lib/redistat/version.rb +1 -1
- data/spec/label_spec.rb +15 -0
- data/spec/summary_spec.rb +37 -0
- metadata +19 -19
data/README.md
CHANGED
@@ -149,7 +149,12 @@ is the label that you're storing to, or fetching from.
|
|
149
149
|
Labels support multiple grouping levels by splitting the label string with `/`
|
150
150
|
and storing the same stats for each level. For example, when storing data to a
|
151
151
|
label called `views/product/44`, the data is stored for the label you specify,
|
152
|
-
and also for `views/product` and `views`.
|
152
|
+
and also for `views/product` and `views`. You may also configure a different
|
153
|
+
group separator using the `Redistat.group_separator=` method. For example:
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
Redistat.group_separator = '|'
|
157
|
+
```
|
153
158
|
|
154
159
|
A word of caution: Don't use a crazy number of group levels. As two levels
|
155
160
|
causes twice as many `hincrby` calls to Redis as not using the grouping
|
data/lib/redistat.rb
CHANGED
data/lib/redistat/key.rb
CHANGED
@@ -56,7 +56,7 @@ module Redistat
|
|
56
56
|
members = db.smembers("#{scope}#{LABEL_INDEX}#{@label}") || [] # older versions of Redis returns nil
|
57
57
|
members.map { |member|
|
58
58
|
child_label = [@label, member].reject { |i| i.nil? }
|
59
|
-
self.class.new(self.scope, child_label.join(
|
59
|
+
self.class.new(self.scope, child_label.join(Redistat.group_separator), self.date, @options)
|
60
60
|
}
|
61
61
|
end
|
62
62
|
|
data/lib/redistat/label.rb
CHANGED
@@ -13,7 +13,7 @@ module Redistat
|
|
13
13
|
|
14
14
|
def self.join(*args)
|
15
15
|
args = args.map {|i| i.to_s}
|
16
|
-
self.new(args.reject {|i| i.blank? }.join(
|
16
|
+
self.new(args.reject {|i| i.blank? }.join(Redistat.group_separator))
|
17
17
|
end
|
18
18
|
|
19
19
|
def initialize(str, opts = {})
|
@@ -48,16 +48,16 @@ module Redistat
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def me
|
51
|
-
self.to_s.split(
|
51
|
+
self.to_s.split(Redistat.group_separator).last
|
52
52
|
end
|
53
53
|
|
54
54
|
def groups
|
55
55
|
return @groups unless @groups.nil?
|
56
56
|
@groups = []
|
57
57
|
parent = ""
|
58
|
-
self.to_s.split(
|
58
|
+
self.to_s.split(Redistat.group_separator).each do |part|
|
59
59
|
if !part.blank?
|
60
|
-
group = ((parent.blank?) ? "" : "#{parent}#{
|
60
|
+
group = ((parent.blank?) ? "" : "#{parent}#{Redistat.group_separator}") + part
|
61
61
|
@groups << Label.new(group)
|
62
62
|
parent = group
|
63
63
|
end
|
data/lib/redistat/summary.rb
CHANGED
@@ -66,13 +66,13 @@ module Redistat
|
|
66
66
|
def inject_group_summaries!(stats)
|
67
67
|
summaries = {}
|
68
68
|
stats.each do |key, value|
|
69
|
-
parts = key.to_s.split(
|
69
|
+
parts = key.to_s.split(Redistat.group_separator)
|
70
70
|
parts.pop
|
71
71
|
if parts.size > 0
|
72
72
|
sum_parts = []
|
73
73
|
parts.each do |part|
|
74
74
|
sum_parts << part
|
75
|
-
sum_key = sum_parts.join(
|
75
|
+
sum_key = sum_parts.join(Redistat.group_separator)
|
76
76
|
(summaries.has_key?(sum_key)) ? summaries[sum_key] += value : summaries[sum_key] = value
|
77
77
|
end
|
78
78
|
end
|
data/lib/redistat/version.rb
CHANGED
data/spec/label_spec.rb
CHANGED
@@ -38,6 +38,21 @@ describe Redistat::Label do
|
|
38
38
|
label.to_s.should == 'email/message/public'
|
39
39
|
end
|
40
40
|
|
41
|
+
it "should allow you to use a different group separator" do
|
42
|
+
include Redistat
|
43
|
+
Redistat.group_separator = '|'
|
44
|
+
label = Label.join('email', 'message', 'public')
|
45
|
+
label.should be_a(Label)
|
46
|
+
label.to_s.should == 'email|message|public'
|
47
|
+
label = Label.join(Label.new('email'), Label.new('message'), Label.new('public'))
|
48
|
+
label.should be_a(Label)
|
49
|
+
label.to_s.should == 'email|message|public'
|
50
|
+
label = Label.join('email', '', 'message', nil, 'public')
|
51
|
+
label.should be_a(Label)
|
52
|
+
label.to_s.should == 'email|message|public'
|
53
|
+
Redistat.group_separator = Redistat::GROUP_SEPARATOR
|
54
|
+
end
|
55
|
+
|
41
56
|
describe "Grouping" do
|
42
57
|
before(:each) do
|
43
58
|
@name = "message/public/offensive"
|
data/spec/summary_spec.rb
CHANGED
@@ -136,4 +136,41 @@ describe Redistat::Summary do
|
|
136
136
|
summary["visitors/us"].should == "8"
|
137
137
|
end
|
138
138
|
|
139
|
+
it "should store label-based grouping enabled stats using a different group separator" do
|
140
|
+
Redistat.group_separator = '|'
|
141
|
+
stats = {"views" => 3, "visitors|eu" => 2, "visitors|us" => 4}
|
142
|
+
label = "views|about_us"
|
143
|
+
key = Redistat::Key.new(@scope, label, @date)
|
144
|
+
Redistat::Summary.update_all(key, stats, :hour)
|
145
|
+
|
146
|
+
key.groups[0].label.to_s.should == "views|about_us"
|
147
|
+
key.groups[1].label.to_s.should == "views"
|
148
|
+
child1 = key.groups[0]
|
149
|
+
parent = key.groups[1]
|
150
|
+
|
151
|
+
label = "views|contact"
|
152
|
+
key = Redistat::Key.new(@scope, label, @date)
|
153
|
+
Redistat::Summary.update_all(key, stats, :hour)
|
154
|
+
|
155
|
+
key.groups[0].label.to_s.should == "views|contact"
|
156
|
+
key.groups[1].label.to_s.should == "views"
|
157
|
+
child2 = key.groups[0]
|
158
|
+
|
159
|
+
summary = db.hgetall(child1.to_s(:hour))
|
160
|
+
summary["views"].should == "3"
|
161
|
+
summary["visitors|eu"].should == "2"
|
162
|
+
summary["visitors|us"].should == "4"
|
163
|
+
|
164
|
+
summary = db.hgetall(child2.to_s(:hour))
|
165
|
+
summary["views"].should == "3"
|
166
|
+
summary["visitors|eu"].should == "2"
|
167
|
+
summary["visitors|us"].should == "4"
|
168
|
+
|
169
|
+
summary = db.hgetall(parent.to_s(:hour))
|
170
|
+
summary["views"].should == "6"
|
171
|
+
summary["visitors|eu"].should == "4"
|
172
|
+
summary["visitors|us"].should == "8"
|
173
|
+
Redistat.group_separator = Redistat::GROUP_SEPARATOR
|
174
|
+
end
|
175
|
+
|
139
176
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redistat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-18 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &70366274446400 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.3.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70366274446400
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &70366274445720 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.4.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70366274445720
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: redis
|
38
|
-
requirement: &
|
38
|
+
requirement: &70366278074380 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.1.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70366278074380
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: time_ext
|
49
|
-
requirement: &
|
49
|
+
requirement: &70366278073860 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.2.9
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70366278073860
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rake
|
60
|
-
requirement: &
|
60
|
+
requirement: &70366278072640 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.8.7
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70366278072640
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70366278071440 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 2.1.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70366278071440
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: yard
|
82
|
-
requirement: &
|
82
|
+
requirement: &70366278070880 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 0.6.3
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70366278070880
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: simplecov
|
93
|
-
requirement: &
|
93
|
+
requirement: &70366278069180 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: 0.6.1
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70366278069180
|
102
102
|
description: A Redis-backed statistics storage and querying library written in Ruby.
|
103
103
|
email:
|
104
104
|
- contact@jimeh.me
|
@@ -176,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
176
|
version: '0'
|
177
177
|
segments:
|
178
178
|
- 0
|
179
|
-
hash: -
|
179
|
+
hash: -3999776337293596550
|
180
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
181
|
none: false
|
182
182
|
requirements:
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
segments:
|
187
187
|
- 0
|
188
|
-
hash: -
|
188
|
+
hash: -3999776337293596550
|
189
189
|
requirements: []
|
190
190
|
rubyforge_project: redistat
|
191
191
|
rubygems_version: 1.8.11
|