redis-time-series 0.3.0 → 0.6.0
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/.github/workflows/rspec.yml +25 -4
- data/.gitignore +1 -0
- data/Appraisals +7 -0
- data/CHANGELOG.md +27 -0
- data/README.md +140 -16
- data/bin/setup +2 -1
- data/lib/ext/time_msec.rb +29 -0
- data/lib/redis-time-series.rb +9 -5
- data/lib/redis/time_series.rb +281 -68
- data/lib/redis/time_series/aggregation.rb +88 -0
- data/lib/redis/time_series/client.rb +77 -0
- data/lib/redis/time_series/duplicate_policy.rb +49 -0
- data/lib/redis/time_series/errors.rb +24 -0
- data/lib/redis/time_series/{filter.rb → filters.rb} +59 -8
- data/lib/redis/time_series/info.rb +96 -14
- data/lib/redis/time_series/rule.rb +49 -0
- data/lib/redis/time_series/sample.rb +22 -6
- data/lib/redis/time_series/version.rb +6 -0
- data/redis-time-series.gemspec +7 -5
- metadata +57 -17
- data/Gemfile.lock +0 -58
- data/lib/time/msec.rb +0 -7
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class Redis
|
3
|
+
class TimeSeries
|
4
|
+
# A compaction rule applies an aggregation from a source series to a destination series.
|
5
|
+
# As data is added to the source, it will be aggregated based on any configured rule(s) and
|
6
|
+
# distributed to the correct destination(s).
|
7
|
+
#
|
8
|
+
# Compaction rules are useful to retain data over long time periods without requiring exorbitant
|
9
|
+
# amounts of memory and storage. For example, if you're collecting data on a minute-by-minute basis,
|
10
|
+
# you may want to retain a week's worth of data at full fidelity, and a year's worth of data downsampled
|
11
|
+
# to hourly, which would require 60x less memory.
|
12
|
+
class Rule
|
13
|
+
# @return [Aggregation] the configured aggregation for this rule
|
14
|
+
attr_reader :aggregation
|
15
|
+
|
16
|
+
# @return [String] the Redis key of the destination series
|
17
|
+
attr_reader :destination_key
|
18
|
+
|
19
|
+
# @return [TimeSeries] the data source of this compaction rule
|
20
|
+
attr_reader :source
|
21
|
+
|
22
|
+
# Manually instantiating a rule does nothing, don't bother.
|
23
|
+
# @api private
|
24
|
+
# @see Info#rules
|
25
|
+
def initialize(source:, data:)
|
26
|
+
@source = source
|
27
|
+
@destination_key, duration, aggregation_type = data
|
28
|
+
@aggregation = Aggregation.new(aggregation_type, duration)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Delete this compaction rule.
|
32
|
+
# @return [String] the string "OK"
|
33
|
+
def delete
|
34
|
+
source.delete_rule(dest: destination_key)
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [TimeSeries] the destination time series this rule refers to
|
38
|
+
def destination
|
39
|
+
@dest ||= TimeSeries.new(destination_key, redis: source.redis)
|
40
|
+
end
|
41
|
+
alias dest destination
|
42
|
+
|
43
|
+
# @return [String] the Redis key of the source series
|
44
|
+
def source_key
|
45
|
+
source.key
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,23 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
class Redis
|
3
3
|
class TimeSeries
|
4
|
+
# A sample is an immutable value object that represents a single data point within a time series.
|
4
5
|
class Sample
|
5
|
-
|
6
|
+
using TimeMsec
|
6
7
|
|
7
|
-
|
8
|
+
# @return [Time] the sample's timestamp
|
9
|
+
attr_reader :time
|
10
|
+
# @return [BigDecimal] the decimal value of the sample
|
11
|
+
attr_reader :value
|
8
12
|
|
13
|
+
# Samples are returned by time series query methods, there's no need to create one yourself.
|
14
|
+
# @api private
|
15
|
+
# @see TimeSeries#get
|
16
|
+
# @see TimeSeries#range
|
9
17
|
def initialize(timestamp, value)
|
10
|
-
@time = Time.
|
18
|
+
@time = Time.from_msec(timestamp)
|
11
19
|
@value = BigDecimal(value)
|
12
20
|
end
|
13
21
|
|
14
|
-
|
15
|
-
|
22
|
+
# @return [Integer] the millisecond value of the sample's timestamp
|
23
|
+
# @note
|
24
|
+
# We're wrapping the method provided by the {TimeMsec} refinement for convenience,
|
25
|
+
# otherwise it wouldn't be callable on {time} and devs would have to litter
|
26
|
+
# +using TimeMsec+ or +* 1000.0+ wherever they wanted the value.
|
27
|
+
def to_msec
|
28
|
+
time.ts_msec
|
16
29
|
end
|
17
30
|
|
31
|
+
# @return [Hash] a hash representation of the sample
|
32
|
+
# @example
|
33
|
+
# {:timestamp=>1595199272401, :value=>0.2e1}
|
18
34
|
def to_h
|
19
35
|
{
|
20
|
-
timestamp:
|
36
|
+
timestamp: to_msec,
|
21
37
|
value: value
|
22
38
|
}
|
23
39
|
end
|
data/redis-time-series.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'redis
|
4
|
+
require 'redis/time_series/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'redis-time-series'
|
8
|
-
spec.version =
|
8
|
+
spec.version = Redis::TimeSeries::VERSION
|
9
9
|
spec.authors = ['Matt Duszynski']
|
10
|
-
spec.email = ['
|
10
|
+
spec.email = ['dzunk@hey.com']
|
11
11
|
|
12
12
|
spec.summary = %q{A Ruby adapter for the RedisTimeSeries module.}
|
13
13
|
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
@@ -31,11 +31,13 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
32
|
spec.require_paths = ['lib']
|
33
33
|
|
34
|
-
spec.add_dependency 'redis', '
|
34
|
+
spec.add_dependency 'redis', '>= 3.3', '< 5'
|
35
35
|
|
36
36
|
spec.add_development_dependency 'activesupport', '~> 6.0'
|
37
|
-
spec.add_development_dependency '
|
37
|
+
spec.add_development_dependency 'appraisal'
|
38
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
38
39
|
spec.add_development_dependency 'pry', '~> 0.13'
|
39
40
|
spec.add_development_dependency 'rake', '~> 13.0'
|
40
41
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
42
|
+
spec.add_development_dependency 'simplecov', '< 0.18' # https://github.com/codeclimate/test-reporter/issues/413
|
41
43
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-time-series
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Duszynski
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.3'
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
22
|
+
version: '5'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
29
|
+
version: '3.3'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: activesupport
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,20 +44,34 @@ dependencies:
|
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: '6.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: appraisal
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: bundler
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
44
64
|
requirements:
|
45
65
|
- - "~>"
|
46
66
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
67
|
+
version: '2.0'
|
48
68
|
type: :development
|
49
69
|
prerelease: false
|
50
70
|
version_requirements: !ruby/object:Gem::Requirement
|
51
71
|
requirements:
|
52
72
|
- - "~>"
|
53
73
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
74
|
+
version: '2.0'
|
55
75
|
- !ruby/object:Gem::Dependency
|
56
76
|
name: pry
|
57
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,9 +114,23 @@ dependencies:
|
|
94
114
|
- - "~>"
|
95
115
|
- !ruby/object:Gem::Version
|
96
116
|
version: '3.0'
|
97
|
-
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: simplecov
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "<"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0.18'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "<"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0.18'
|
131
|
+
description:
|
98
132
|
email:
|
99
|
-
-
|
133
|
+
- dzunk@hey.com
|
100
134
|
executables: []
|
101
135
|
extensions: []
|
102
136
|
extra_rdoc_files: []
|
@@ -104,20 +138,26 @@ files:
|
|
104
138
|
- ".github/workflows/rspec.yml"
|
105
139
|
- ".gitignore"
|
106
140
|
- ".rspec"
|
141
|
+
- Appraisals
|
107
142
|
- CHANGELOG.md
|
108
143
|
- Gemfile
|
109
|
-
- Gemfile.lock
|
110
144
|
- LICENSE.txt
|
111
145
|
- README.md
|
112
146
|
- Rakefile
|
113
147
|
- bin/console
|
114
148
|
- bin/setup
|
149
|
+
- lib/ext/time_msec.rb
|
115
150
|
- lib/redis-time-series.rb
|
116
151
|
- lib/redis/time_series.rb
|
117
|
-
- lib/redis/time_series/
|
152
|
+
- lib/redis/time_series/aggregation.rb
|
153
|
+
- lib/redis/time_series/client.rb
|
154
|
+
- lib/redis/time_series/duplicate_policy.rb
|
155
|
+
- lib/redis/time_series/errors.rb
|
156
|
+
- lib/redis/time_series/filters.rb
|
118
157
|
- lib/redis/time_series/info.rb
|
158
|
+
- lib/redis/time_series/rule.rb
|
119
159
|
- lib/redis/time_series/sample.rb
|
120
|
-
- lib/
|
160
|
+
- lib/redis/time_series/version.rb
|
121
161
|
- redis-time-series.gemspec
|
122
162
|
homepage: https://github.com/dzunk/redis-time-series
|
123
163
|
licenses:
|
@@ -126,7 +166,7 @@ metadata:
|
|
126
166
|
homepage_uri: https://github.com/dzunk/redis-time-series
|
127
167
|
source_code_uri: https://github.com/dzunk/redis-time-series
|
128
168
|
changelog_uri: https://github.com/dzunk/redis-time-series/blob/master/CHANGELOG.md
|
129
|
-
post_install_message:
|
169
|
+
post_install_message:
|
130
170
|
rdoc_options: []
|
131
171
|
require_paths:
|
132
172
|
- lib
|
@@ -141,8 +181,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
181
|
- !ruby/object:Gem::Version
|
142
182
|
version: '0'
|
143
183
|
requirements: []
|
144
|
-
rubygems_version: 3.
|
145
|
-
signing_key:
|
184
|
+
rubygems_version: 3.2.2
|
185
|
+
signing_key:
|
146
186
|
specification_version: 4
|
147
187
|
summary: A Ruby adapter for the RedisTimeSeries module.
|
148
188
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
redis-time-series (0.3.0)
|
5
|
-
redis (~> 4.0)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
activesupport (6.0.3.1)
|
11
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
-
i18n (>= 0.7, < 2)
|
13
|
-
minitest (~> 5.1)
|
14
|
-
tzinfo (~> 1.1)
|
15
|
-
zeitwerk (~> 2.2, >= 2.2.2)
|
16
|
-
coderay (1.1.3)
|
17
|
-
concurrent-ruby (1.1.6)
|
18
|
-
diff-lcs (1.3)
|
19
|
-
i18n (1.8.3)
|
20
|
-
concurrent-ruby (~> 1.0)
|
21
|
-
method_source (1.0.0)
|
22
|
-
minitest (5.14.1)
|
23
|
-
pry (0.13.1)
|
24
|
-
coderay (~> 1.1)
|
25
|
-
method_source (~> 1.0)
|
26
|
-
rake (13.0.1)
|
27
|
-
redis (4.2.1)
|
28
|
-
rspec (3.9.0)
|
29
|
-
rspec-core (~> 3.9.0)
|
30
|
-
rspec-expectations (~> 3.9.0)
|
31
|
-
rspec-mocks (~> 3.9.0)
|
32
|
-
rspec-core (3.9.2)
|
33
|
-
rspec-support (~> 3.9.3)
|
34
|
-
rspec-expectations (3.9.2)
|
35
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
-
rspec-support (~> 3.9.0)
|
37
|
-
rspec-mocks (3.9.1)
|
38
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
-
rspec-support (~> 3.9.0)
|
40
|
-
rspec-support (3.9.3)
|
41
|
-
thread_safe (0.3.6)
|
42
|
-
tzinfo (1.2.7)
|
43
|
-
thread_safe (~> 0.1)
|
44
|
-
zeitwerk (2.3.0)
|
45
|
-
|
46
|
-
PLATFORMS
|
47
|
-
ruby
|
48
|
-
|
49
|
-
DEPENDENCIES
|
50
|
-
activesupport (~> 6.0)
|
51
|
-
bundler (~> 1.17)
|
52
|
-
pry (~> 0.13)
|
53
|
-
rake (~> 13.0)
|
54
|
-
redis-time-series!
|
55
|
-
rspec (~> 3.0)
|
56
|
-
|
57
|
-
BUNDLED WITH
|
58
|
-
1.17.2
|