Method: Redis::TimeSeries#source_key
- Defined in:
- lib/redis/time_series/info.rb
#source_key ⇒ String? (readonly)
Returns the key of the source series, if this series is the destination of a compaction rule.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/redis/time_series/info.rb', line 42 Info = Struct.new( :chunk_count, :chunk_size, :chunk_type, :duplicate_policy, :first_timestamp, :labels, :last_timestamp, :max_samples_per_chunk, :memory_usage, :retention_time, :rules, :series, :source_key, :total_samples, keyword_init: true ) do class << self # @api private # @return [Info] def parse(series:, data:) build_hash(data) .merge(series: series) .then(&method(:parse_labels)) .then(&method(:parse_policies)) .then(&method(:parse_rules)) .then(&method(:new)) end private def build_hash(data) data.each_slice(2).reduce({}) do |h, (key, value)| # Convert camelCase info keys to snake_case key = key.gsub(/(.)([A-Z])/,'\1_\2').downcase.to_sym # Skip unknown properties next h unless members.include?(key) h.merge(key => value) end end def parse_labels(hash) hash[:labels] = hash[:labels].to_h.transform_values { |v| v.to_i.to_s == v ? v.to_i : v } hash end def parse_policies(hash) hash[:duplicate_policy] = DuplicatePolicy.new(hash[:duplicate_policy]) if hash[:duplicate_policy] hash end def parse_rules(hash) hash[:rules] = hash[:rules].map { |d| Rule.new(source: hash[:series], data: d) } hash end end alias count total_samples alias length total_samples alias size total_samples # If this series is the destination of a compaction rule, returns the source series of the data. # @return [TimeSeries, nil] the series referred to by {source_key} def source return unless source_key @source ||= TimeSeries.new(source_key, redis: series.redis) end end |