Class: Redis::TimeSeries::Rule

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

See Also:



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

#aggregationAggregation (readonly)

Returns the configured aggregation for this rule.

Returns:

  • (Aggregation)

    the configured aggregation for this rule



14
15
16
# File 'lib/redis/time_series/rule.rb', line 14

def aggregation
  @aggregation
end

#destination_keyString (readonly)

Returns the Redis key of the destination series.

Returns:

  • (String)

    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

#sourceTimeSeries (readonly)

Returns the data source of this compaction rule.

Returns:

  • (TimeSeries)

    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

#deleteString

Delete this compaction rule.

Returns:

  • (String)

    the string “OK”



33
34
35
# File 'lib/redis/time_series/rule.rb', line 33

def delete
  source.delete_rule(dest: destination_key)
end

#destinationTimeSeries Also known as: dest

Returns the destination time series this rule refers to.

Returns:

  • (TimeSeries)

    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_keyString

Returns the Redis key of the source series.

Returns:

  • (String)

    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