Class: Redis::TimeSeries::Rule
- Inherits:
-
Object
- Object
- Redis::TimeSeries::Rule
- Defined in:
- lib/redis/time_series/rule.rb
Overview
A compaction rule applies an aggregation from a source series to a destination series. As data is added to the source, it will be aggregated based on any configured rule(s) and distributed to the correct destination(s).
Compaction rules are useful to retain data over long time periods without requiring exorbitant amounts of memory and storage. For example, if you’re collecting data on a minute-by-minute basis, you may want to retain a week’s worth of data at full fidelity, and a year’s worth of data downsampled to hourly, which would require 60x less memory.
Instance Attribute Summary collapse
-
#aggregation ⇒ Aggregation
readonly
The configured aggregation for this rule.
-
#destination_key ⇒ String
readonly
The Redis key of the destination series.
-
#source ⇒ TimeSeries
readonly
The data source of this compaction rule.
Instance Method Summary collapse
-
#delete ⇒ String
Delete this compaction rule.
-
#destination ⇒ TimeSeries
(also: #dest)
The destination time series this rule refers to.
-
#initialize(source:, data:) ⇒ Rule
constructor
private
Manually instantiating a rule does nothing, don’t bother.
-
#source_key ⇒ String
The Redis key of the source series.
Constructor Details
#initialize(source:, data:) ⇒ Rule
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Manually instantiating a rule does nothing, don’t bother.
25 26 27 28 29 |
# File 'lib/redis/time_series/rule.rb', line 25 def initialize(source:, data:) @source = source @destination_key, duration, aggregation_type = data @aggregation = Aggregation.new(aggregation_type, duration) end |
Instance Attribute Details
#aggregation ⇒ Aggregation (readonly)
Returns the configured aggregation for this rule.
14 15 16 |
# File 'lib/redis/time_series/rule.rb', line 14 def aggregation @aggregation end |
#destination_key ⇒ String (readonly)
Returns the Redis key of the destination series.
17 18 19 |
# File 'lib/redis/time_series/rule.rb', line 17 def destination_key @destination_key end |
#source ⇒ TimeSeries (readonly)
Returns the data source of this compaction rule.
20 21 22 |
# File 'lib/redis/time_series/rule.rb', line 20 def source @source end |
Instance Method Details
#delete ⇒ String
Delete this compaction rule.
33 34 35 |
# File 'lib/redis/time_series/rule.rb', line 33 def delete source.delete_rule(dest: destination_key) end |
#destination ⇒ TimeSeries Also known as: dest
Returns the destination time series this rule refers to.
38 39 40 |
# File 'lib/redis/time_series/rule.rb', line 38 def destination @dest ||= TimeSeries.new(destination_key, redis: source.redis) end |
#source_key ⇒ String
Returns the Redis key of the source series.
44 45 46 |
# File 'lib/redis/time_series/rule.rb', line 44 def source_key source.key end |