0.0
No commit activity in last 3 years
No release in over 3 years
Make Redis Streams feel like a first-class citizen in Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.17
~> 0.12
~> 13.0
~> 3.9

Runtime

~> 4.1
 Project Readme

RedisStream

Usage

Setting up

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"

Adding messages to the stream

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

Consuming messages from the stream

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}"