active_redis_stats 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_redis_stats/base.rb +58 -56
- data/lib/active_redis_stats/count/base.rb +4 -2
- data/lib/active_redis_stats/count/get.rb +10 -8
- data/lib/active_redis_stats/count/set.rb +2 -2
- data/lib/active_redis_stats/rank/base.rb +4 -2
- data/lib/active_redis_stats/rank/get.rb +46 -44
- data/lib/active_redis_stats/rank/set.rb +2 -2
- data/lib/active_redis_stats/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 646cf926b9891a817ab1fdbb777bc0279fc5f633de41af5819bdfe907c13fcfe
|
4
|
+
data.tar.gz: 462068744e79fddb300a5e67368afb2cf2248ef967ffbd966d3c14970ba66408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9bd6a89c385cd96e1a65c47806aea83c92b9428a9aadf1044f5123248b1bcbe2dbb9a6a5fdfc0fe60bc2667ab2a272ea57d9902fe7f30d4c68961c6461b33d5
|
7
|
+
data.tar.gz: 72dbbefb90f5a6574499cad4698611cec300d6bb0a5413abe37a7ed2b600f312a71f93af12f73ca515f5f2e3187e0dc7438f3fb66ed041693dc1fe30027ea7a0
|
@@ -21,85 +21,87 @@ module ActiveRedisStats
|
|
21
21
|
inf: nil # never
|
22
22
|
}.freeze
|
23
23
|
|
24
|
-
|
25
|
-
format
|
26
|
-
|
24
|
+
class << self
|
25
|
+
def interval_key(format, time: TIME)
|
26
|
+
format = format.to_sym
|
27
|
+
return "#{format}:#{format}" if format == :inf
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
interval = time.format(FORMATS[format])
|
30
|
+
"#{format}:#{interval}"
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
def hour_key(offset: 0)
|
34
|
+
interval_key(:day, time: offset.minutes.ago(TIME))
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
def hour_keys(offset: 0)
|
38
|
+
adj = (30 * offset)
|
39
|
+
max = 29 + adj
|
40
|
+
min = 0 + adj
|
40
41
|
|
41
|
-
|
42
|
-
|
42
|
+
max.downto(min).collect do |num|
|
43
|
+
interval_key(:hour, time: num.minutes.ago(TIME))
|
44
|
+
end
|
43
45
|
end
|
44
|
-
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
def day_key(offset: 0)
|
48
|
+
interval_key(:month, time: offset.days.ago(TIME))
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
51
|
+
def day_keys(offset: 0)
|
52
|
+
boy = offset.days.ago(TIME).beginning_of_day
|
52
53
|
|
53
|
-
|
54
|
-
|
54
|
+
0.upto(23).collect do |num|
|
55
|
+
interval_key(:day, time: num.hours.from_now(boy))
|
56
|
+
end
|
55
57
|
end
|
56
|
-
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def month_key(offset: 0)
|
60
|
+
interval_key(:year, time: offset.months.ago(TIME))
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
def month_keys(offset: 0)
|
64
|
+
boy = offset.months.ago(TIME).beginning_of_month
|
65
|
+
max = boy.end_of_month.day - 1
|
65
66
|
|
66
|
-
|
67
|
-
|
67
|
+
0.upto(max).collect do |num|
|
68
|
+
interval_key(:month, time: num.days.from_now(boy))
|
69
|
+
end
|
68
70
|
end
|
69
|
-
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
def year_key(offset: 0)
|
73
|
+
interval_key(:all, time: offset.years.ago(TIME))
|
74
|
+
end
|
74
75
|
|
75
|
-
|
76
|
-
|
76
|
+
def year_keys(offset: 0)
|
77
|
+
boy = offset.years.ago(TIME).beginning_of_year
|
77
78
|
|
78
|
-
|
79
|
-
|
79
|
+
0.upto(11).collect do |num|
|
80
|
+
interval_key(:year, time: num.months.from_now(boy))
|
81
|
+
end
|
80
82
|
end
|
81
|
-
end
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
84
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
85
|
+
def all_key(offset: 0)
|
86
|
+
interval_key(:inf)
|
87
|
+
end
|
88
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
def all_keys(offset: 0)
|
91
|
+
max = 9 + offset
|
92
|
+
min = 0 + offset
|
92
93
|
|
93
|
-
|
94
|
-
|
94
|
+
max.downto(min).collect do |num|
|
95
|
+
interval_key(:all, time: num.years.ago(TIME))
|
96
|
+
end
|
95
97
|
end
|
96
|
-
end
|
97
98
|
|
98
|
-
|
99
|
-
|
99
|
+
def expiration(key, seconds)
|
100
|
+
return if seconds.nil?
|
100
101
|
|
101
|
-
|
102
|
-
|
102
|
+
ActiveRedisDB::Key
|
103
|
+
.expire(primary_key(key), seconds)
|
104
|
+
end
|
103
105
|
end
|
104
106
|
|
105
107
|
end
|
@@ -4,15 +4,17 @@ module ActiveRedisStats
|
|
4
4
|
module Count
|
5
5
|
class Get < ActiveRedisStats::Count::Base
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
class << self
|
8
|
+
def total(key)
|
9
|
+
ActiveRedisDB::String
|
10
|
+
.evaluate
|
11
|
+
.find(primary_key(key)) || 0
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def total_intervals(key, format: :month, offset: 0)
|
15
|
+
keys = send("#{format}_keys", offset: offset)
|
16
|
+
keys.collect { |k| total("#{key}:#{k}") }
|
17
|
+
end
|
16
18
|
end
|
17
19
|
|
18
20
|
end
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module ActiveRedisStats
|
4
4
|
module Count
|
5
5
|
class Set < ActiveRedisStats::Count::Base
|
6
|
-
class << self
|
7
6
|
|
7
|
+
class << self
|
8
8
|
%i[decrement increment].each do |meth|
|
9
9
|
define_method(meth) do |key, by: 1|
|
10
10
|
ActiveRedisDB::String
|
@@ -20,8 +20,8 @@ module ActiveRedisStats
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
24
|
+
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -6,50 +6,52 @@ module ActiveRedisStats
|
|
6
6
|
|
7
7
|
LIMIT ||= 100
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
9
|
+
class << self
|
10
|
+
def all(key, with_scores: false)
|
11
|
+
ActiveRedisDB::SortedSet
|
12
|
+
.evaluate
|
13
|
+
.all_reverse(primary_key(key), with_scores: with_scores) || []
|
14
|
+
end
|
15
|
+
|
16
|
+
def all_intervals(key, with_scores: false, format: :month, offset: 0)
|
17
|
+
ikey = send("#{format}_key", offset: offset)
|
18
|
+
all("#{key}:#{ikey}", with_scores: with_scores)
|
19
|
+
end
|
20
|
+
|
21
|
+
def between(key, with_scores: false, from:, to:)
|
22
|
+
ActiveRedisDB::SortedSet
|
23
|
+
.evaluate
|
24
|
+
.between_reverse(primary_key(key), from, to, with_scores: with_scores) || []
|
25
|
+
end
|
26
|
+
|
27
|
+
# rubocop:disable Metrics/ParameterLists
|
28
|
+
def between_intervals(key, with_scores: false, from:, to:, format: :month, offset: 0)
|
29
|
+
ikey = send("#{format}_key", offset: offset)
|
30
|
+
between("#{key}:#{ikey}", with_scores: with_scores, from: from, to: to)
|
31
|
+
end
|
32
|
+
# rubocop:enable Metrics/ParameterLists
|
33
|
+
|
34
|
+
def bottom(key, with_scores: false, limit: LIMIT)
|
35
|
+
ActiveRedisDB::SortedSet
|
36
|
+
.evaluate
|
37
|
+
.between(primary_key(key), 1, limit, with_scores: with_scores) || []
|
38
|
+
end
|
39
|
+
|
40
|
+
def bottom_intervals(key, with_scores: false, limit: LIMIT, format: :month, offset: 0)
|
41
|
+
ikey = send("#{format}_key", offset: offset)
|
42
|
+
bottom("#{key}:#{ikey}", with_scores: with_scores, limit: limit)
|
43
|
+
end
|
44
|
+
|
45
|
+
def top(key, with_scores: false, limit: LIMIT)
|
46
|
+
ActiveRedisDB::SortedSet
|
47
|
+
.evaluate
|
48
|
+
.between_reverse(primary_key(key), 1, limit, with_scores: with_scores) || []
|
49
|
+
end
|
50
|
+
|
51
|
+
def top_intervals(key, with_scores: false, limit: LIMIT, format: :month, offset: 0)
|
52
|
+
ikey = send("#{format}_key", offset: offset)
|
53
|
+
top("#{key}:#{ikey}", with_scores: with_scores, limit: limit)
|
54
|
+
end
|
53
55
|
end
|
54
56
|
|
55
57
|
end
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module ActiveRedisStats
|
4
4
|
module Rank
|
5
5
|
class Set < ActiveRedisStats::Rank::Base
|
6
|
-
class << self
|
7
6
|
|
7
|
+
class << self
|
8
8
|
%i[decrement increment].each do |meth|
|
9
9
|
define_method(meth) do |key, val, by: 1|
|
10
10
|
ActiveRedisDB::SortedSet
|
@@ -20,8 +20,8 @@ module ActiveRedisStats
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
24
|
+
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_redis_stats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_object
|