forked from antirez/redis-timeseries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.rb
33 lines (28 loc) · 917 Bytes
/
example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'rubygems'
require 'redis'
require 'redis-timeseries'
# To show the lib implementation here we use a timestep of just one second.
# Then we sample every 0.1 seconds, producing on average 10 samples per key.
# This way we should how multi-key range queries are working.
ts = RedisTimeSeries.new("test",1,Redis.new)
now = Time.now.to_f
puts "Adding data points: "
(0..30).each{|i|
print "#{i} "
STDOUT.flush
ts.add(i.to_s)
sleep 0.1
}
puts ""
# Get the second in the middle of our sampling.
begin_time = now+1
end_time = now+2
puts "\nGet range from #{begin_time} to #{end_time}"
ts.fetch_range(begin_time,end_time).each{|record|
puts "Record time #{record[:time]}, data #{record[:data]}"
}
# Show API to get a single timestep
puts "\nGet a single timestep near #{begin_time}"
ts.fetch_timestep(begin_time).each{|record|
puts "Record time #{record[:time]}, data #{record[:data]}"
}