Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chunk_type to info struct #47

Merged
merged 2 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Unreleased
* Add chunk_type to info struct (#47)

## 0.5.1
* Update Info struct for RTS 1.4 compatibility (#45)
Expand Down
11 changes: 7 additions & 4 deletions lib/redis/time_series/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class TimeSeries
Info = Struct.new(
:chunk_count,
:chunk_size,
:chunk_type,
:duplicate_policy,
:first_timestamp,
:labels,
Expand All @@ -56,12 +57,14 @@ class TimeSeries
def self.parse(series:, data:)
data.each_slice(2).reduce({}) do |h, (key, value)|
# Convert camelCase info keys to snake_case
h[key.gsub(/(.)([A-Z])/,'\1_\2').downcase] = value
key = key.gsub(/(.)([A-Z])/,'\1_\2').downcase.to_sym
next h unless members.include?(key)
h[key] = value
h
end.then do |parsed_hash|
parsed_hash['series'] = series
parsed_hash['labels'] = parsed_hash['labels'].to_h
parsed_hash['rules'] = parsed_hash['rules'].map { |d| Rule.new(source: series, data: d) }
parsed_hash[:series] = series
parsed_hash[:labels] = parsed_hash[:labels].to_h
parsed_hash[:rules] = parsed_hash[:rules].map { |d| Rule.new(source: series, data: d) }
new(parsed_hash)
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/redis/time_series_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def msec(ts)
{
chunk_count: 1,
chunk_size: 4096,
chunk_type: 'compressed',
duplicate_policy: nil,
first_timestamp: 0,
labels: {},
Expand Down