class Redis::TimeSeries::Rule

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.

Attributes

aggregation[R]

@return [Aggregation] the configured aggregation for this rule

destination_key[R]

@return [String] the Redis key of the destination series

source[R]

@return [TimeSeries] the data source of this compaction rule

Public Class Methods

new(source:, data:) click to toggle source

Manually instantiating a rule does nothing, don't bother. @api private @see Info#rules

# 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

Public Instance Methods

delete() click to toggle source

Delete this compaction rule. @return [String] the string “OK”

# File lib/redis/time_series/rule.rb, line 33
def delete
  source.delete_rule(dest: destination_key)
end
dest()
Alias for: destination
destination() click to toggle source

@return [TimeSeries] the destination time series this rule refers to

# File lib/redis/time_series/rule.rb, line 38
def destination
  @dest ||= TimeSeries.new(destination_key, redis: source.redis)
end
Also aliased as: dest
source_key() click to toggle source

@return [String] the Redis key of the source series

# File lib/redis/time_series/rule.rb, line 44
def source_key
  source.key
end