class Redis::TimeSeries::Sample
A sample is an immutable value object that represents a single data point within a time series.
Attributes
time[R]
@return [Time] the sample's timestamp
value[R]
@return [BigDecimal] the decimal value of the sample
Public Class Methods
new(timestamp, value)
click to toggle source
Samples are returned by time series query methods, there's no need to create one yourself. @api private @see TimeSeries#get
@see TimeSeries#range
# File lib/redis/time_series/sample.rb, line 17 def initialize(timestamp, value) @time = Time.from_msec(timestamp) @value = BigDecimal(value) end
Public Instance Methods
to_h()
click to toggle source
@return [Hash] a hash representation of the sample @example
{:timestamp=>1595199272401, :value=>0.2e1}
# File lib/redis/time_series/sample.rb, line 34 def to_h { timestamp: to_msec, value: value } end
to_msec()
click to toggle source
@return [Integer] the millisecond value of the sample's timestamp @note
We're wrapping the method provided by the {TimeMsec} refinement for convenience, otherwise it wouldn't be callable on {time} and devs would have to litter +using TimeMsec+ or +* 1000.0+ wherever they wanted the value.
# File lib/redis/time_series/sample.rb, line 27 def to_msec time.ts_msec end