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
|
# frozen_string_literal: true
require 'rubygems'
require 'redis'
r = Redis.new
r.del 'logs'
puts
p "pushing log messages into a LIST"
r.rpush 'logs', 'some log message'
r.rpush 'logs', 'another log message'
r.rpush 'logs', 'yet another log message'
r.rpush 'logs', 'also another log message'
puts
p 'contents of logs LIST'
p r.lrange('logs', 0, -1)
puts
p 'Trim logs LIST to last 2 elements(easy circular buffer)'
r.ltrim('logs', -2, -1)
p r.lrange('logs', 0, -1)
|