redis-time-series 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +2 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +2 -2
- data/README.md +25 -10
- data/bin/console +1 -1
- data/lib/redis-time-series.rb +3 -1
- data/lib/redis/time_series.rb +10 -13
- data/lib/redis/time_series/info.rb +29 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51234a8f3542da255912f95982ebab2bf66dd657da9e38e55afdedd97029685d
|
4
|
+
data.tar.gz: 42a49fdafb136d8ebe4b094f935b0427430672ab810691a35ca2f78328d92135
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acc08d1745cf24bfc87c22d3809570daa0b2feae4e5d5b97d4a43a0626217b44ea3ffdb12c3f6799c068bb6e62f0cc7a1b65274e5d8eac5cb13017bfea73dff4
|
7
|
+
data.tar.gz: 1ff7aa6fb44dd2729612ac24e2be45496d45bd5a0fc86ed692bd18c38bcb160971c0efed05e598ffabb6471cf4d6903d303a1d0b74e55672c479829b98b26012
|
data/.github/workflows/rspec.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
redis-time-series (0.1.
|
4
|
+
redis-time-series (0.1.1)
|
5
5
|
redis (~> 4.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -24,7 +24,7 @@ GEM
|
|
24
24
|
coderay (~> 1.1)
|
25
25
|
method_source (~> 1.0)
|
26
26
|
rake (13.0.1)
|
27
|
-
redis (4.1
|
27
|
+
redis (4.2.1)
|
28
28
|
rspec (3.9.0)
|
29
29
|
rspec-core (~> 3.9.0)
|
30
30
|
rspec-expectations (~> 3.9.0)
|
data/README.md
CHANGED
@@ -133,16 +133,31 @@ ts.range from: 10.minutes.ago, to: Time.current # Time range as keyword args
|
|
133
133
|
Get info about the series
|
134
134
|
```ruby
|
135
135
|
ts.info
|
136
|
-
=>
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
"
|
145
|
-
|
136
|
+
=> #<struct Redis::TimeSeries::Info
|
137
|
+
total_samples=3,
|
138
|
+
memory_usage=4184,
|
139
|
+
first_timestamp=1594060993011,
|
140
|
+
last_timestamp=1594060993060,
|
141
|
+
retention_time=0,
|
142
|
+
chunk_count=1,
|
143
|
+
max_samples_per_chunk=256,
|
144
|
+
labels={"foo"=>"bar"},
|
145
|
+
source_key=nil,
|
146
|
+
rules=[]>
|
147
|
+
# Each info property is also a method on the time series object
|
148
|
+
ts.memory_usage
|
149
|
+
=> 4208
|
150
|
+
ts.labels
|
151
|
+
=> {"foo"=>"bar"}
|
152
|
+
ts.total_samples
|
153
|
+
=> 3
|
154
|
+
# Total samples also available as #count, #length, and #size
|
155
|
+
ts.count
|
156
|
+
=> 3
|
157
|
+
ts.length
|
158
|
+
=> 3
|
159
|
+
ts.size
|
160
|
+
=> 3
|
146
161
|
```
|
147
162
|
|
148
163
|
### TODO
|
data/bin/console
CHANGED
data/lib/redis-time-series.rb
CHANGED
data/lib/redis/time_series.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
class Redis
|
3
3
|
class TimeSeries
|
4
|
+
extend Forwardable
|
5
|
+
|
4
6
|
class << self
|
5
7
|
def create(key, **options)
|
6
|
-
new(key, **options).create
|
8
|
+
new(key, **options).create(labels: options[:labels])
|
7
9
|
end
|
8
10
|
|
9
11
|
def madd(data)
|
@@ -40,12 +42,10 @@ class Redis
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
|
-
attr_reader :key, :
|
45
|
+
attr_reader :key, :redis, :retention, :uncompressed
|
44
46
|
|
45
47
|
def initialize(key, options = {})
|
46
48
|
@key = key
|
47
|
-
# TODO: read labels from redis if not loaded in memory
|
48
|
-
@labels = options[:labels] || []
|
49
49
|
@redis = options[:redis] || self.class.redis
|
50
50
|
@retention = options[:retention]
|
51
51
|
@uncompressed = options[:uncompressed] || false
|
@@ -57,11 +57,11 @@ class Redis
|
|
57
57
|
Sample.new(ts, value)
|
58
58
|
end
|
59
59
|
|
60
|
-
def create
|
60
|
+
def create(labels: nil)
|
61
61
|
args = [key]
|
62
62
|
args << ['RETENTION', retention] if retention
|
63
63
|
args << 'UNCOMPRESSED' if uncompressed
|
64
|
-
args << ['LABELS', labels.to_a] if labels
|
64
|
+
args << ['LABELS', labels.to_a] if labels&.any?
|
65
65
|
cmd 'TS.CREATE', args.flatten
|
66
66
|
self
|
67
67
|
end
|
@@ -91,17 +91,14 @@ class Redis
|
|
91
91
|
end
|
92
92
|
alias increment incrby
|
93
93
|
|
94
|
-
# TODO: extract Info module, with methods for each property
|
95
94
|
def info
|
96
|
-
cmd('TS.INFO', key).
|
97
|
-
h[key.gsub(/(.)([A-Z])/,'\1_\2').downcase] = value
|
98
|
-
h
|
99
|
-
end
|
95
|
+
cmd('TS.INFO', key).then(&Info.method(:parse))
|
100
96
|
end
|
97
|
+
def_delegators :info, *Info.members
|
98
|
+
%i[count length size].each { |m| def_delegator :info, :total_samples, m }
|
101
99
|
|
102
100
|
def labels=(val)
|
103
|
-
|
104
|
-
cmd 'TS.ALTER', key, 'LABELS', labels.to_a.flatten
|
101
|
+
cmd 'TS.ALTER', key, 'LABELS', val.to_a.flatten
|
105
102
|
end
|
106
103
|
|
107
104
|
def madd(*values)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class Redis
|
3
|
+
class TimeSeries
|
4
|
+
Info = Struct.new(
|
5
|
+
:total_samples,
|
6
|
+
:memory_usage,
|
7
|
+
:first_timestamp,
|
8
|
+
:last_timestamp,
|
9
|
+
:retention_time,
|
10
|
+
:chunk_count,
|
11
|
+
:max_samples_per_chunk,
|
12
|
+
:labels,
|
13
|
+
:source_key,
|
14
|
+
:rules,
|
15
|
+
keyword_init: true
|
16
|
+
) do
|
17
|
+
def self.parse(raw_array)
|
18
|
+
raw_array.each_slice(2).reduce({}) do |h, (key, value)|
|
19
|
+
# Convert camelCase info keys to snake_case
|
20
|
+
h[key.gsub(/(.)([A-Z])/,'\1_\2').downcase] = value
|
21
|
+
h
|
22
|
+
end.then do |parsed_hash|
|
23
|
+
parsed_hash['labels'] = parsed_hash['labels'].to_h
|
24
|
+
new(parsed_hash)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-time-series
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Duszynski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06
|
11
|
+
date: 2020-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- bin/setup
|
115
115
|
- lib/redis-time-series.rb
|
116
116
|
- lib/redis/time_series.rb
|
117
|
+
- lib/redis/time_series/info.rb
|
117
118
|
- lib/redis/time_series/sample.rb
|
118
119
|
- lib/time/msec.rb
|
119
120
|
- redis-time-series.gemspec
|