Class: Redis::TimeSeries::Multi
- Inherits:
-
Array
- Object
- Array
- Redis::TimeSeries::Multi
- Defined in:
- lib/redis/time_series/multi.rb
Overview
A Multi is a collection of multiple series and their samples, returned from a multi command (e.g. TS.MGET or TS.MRANGE).
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#[](index_or_key) ⇒ Multi::Result?
Access a specific result by either array position, or hash lookup.
-
#initialize(result_array) ⇒ Multi
constructor
private
Multis are initialized by one of the class-level query commands.
-
#keys ⇒ Array<String>
Get all the series keys that are present in this result collection.
-
#sample_count ⇒ Integer
Get a count of all matching samples from all series in this result collection.
-
#series ⇒ Array<TimeSeries>
Get all the series objects that are present in this result collection.
-
#to_h ⇒ Hash<Array>
Convert these results into a hash, keyed by series name.
Constructor Details
#initialize(result_array) ⇒ Multi
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.
Multis are initialized by one of the class-level query commands. There’s no need to ever create one yourself.
13 14 15 16 17 18 19 20 21 |
# File 'lib/redis/time_series/multi.rb', line 13 def initialize(result_array) super(result_array.map do |res| Result.new( TimeSeries.new(res[0]), res[1], res[2].map { |s| Sample.new(s[0], s[1]) } ) end) end |
Instance Method Details
#[](index_or_key) ⇒ Multi::Result?
Access a specific result by either array position, or hash lookup.
29 30 31 32 |
# File 'lib/redis/time_series/multi.rb', line 29 def [](index_or_key) return super if index_or_key.is_a?(Integer) find { |result| result.series.key == index_or_key.to_s } end |
#keys ⇒ Array<String>
Get all the series keys that are present in this result collection.
36 37 38 |
# File 'lib/redis/time_series/multi.rb', line 36 def keys map { |r| r.series.key } end |
#sample_count ⇒ Integer
Get a count of all matching samples from all series in this result collection.
61 62 63 |
# File 'lib/redis/time_series/multi.rb', line 61 def sample_count reduce(0) { |size, r| size += r.samples.size } end |
#series ⇒ Array<TimeSeries>
Get all the series objects that are present in this result collection.
42 43 44 |
# File 'lib/redis/time_series/multi.rb', line 42 def series map(&:series) end |
#to_h ⇒ Hash<Array>
Convert these results into a hash, keyed by series name.
53 54 55 56 57 |
# File 'lib/redis/time_series/multi.rb', line 53 def to_h super do |result| [result.series.key, result.samples.map(&:to_h)] end end |