Under the hood RedisStream is using redis gem, which means that you can use it
out of the box if you are using redis. It will be using same REDIS_URL
environment variable to establish connection with Redis.
# Gemfile
gem "redis_stream", "~> 0.3.0"
require 'redis_stream'
daily_temperature = RedisStream.stream(name: "daily_temperature")
daily_temperature << 20.0
daily_temperature << 21.0
daily_temperature << 22.0
puts daily_temperature.size
#=> 3
Stream implements most of operations that can be performed on ruby Array.
daily_temperature.each do |temperature|
puts message
end
# => 20.0
# => 21.0
# => 22.0
puts daily_temperature.last
# => 22.0
puts daily_temperature.first
# => 20.0
average = daily_temperature.sum / daily_temperature.length
min = daily_temperature.min
max = daily_temperature.max
puts "Average: #{average} Min: #{min} Max: #{max}"