Module: MockRedis::StreamMethods

Includes:
Assertions, UtilityMethods
Included in:
Database
Defined in:
lib/mock_redis/stream_methods.rb

Instance Method Summary collapse

Instance Method Details

#xadd(key, entry, opts = {}) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/mock_redis/stream_methods.rb', line 33

def xadd(key, entry, opts = {})
  id = opts[:id] || '*'
  with_stream_at(key) do |stream|
    stream.add id, entry
    stream.trim opts[:maxlen] if opts[:maxlen]
    return stream.last_id
  end
end

#xlen(key) ⇒ Object



48
49
50
51
52
# File 'lib/mock_redis/stream_methods.rb', line 48

def xlen(key)
  with_stream_at(key) do |stream|
    return stream.count
  end
end

#xrange(key, first = '-', last = '+', count: nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/mock_redis/stream_methods.rb', line 54

def xrange(key, first = '-', last = '+', count: nil)
  args = [first, last, false]
  args += ['COUNT', count] if count
  with_stream_at(key) do |stream|
    return stream.range(*args)
  end
end

#xrevrange(key, last = '+', first = '-', count: nil) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/mock_redis/stream_methods.rb', line 62

def xrevrange(key, last = '+', first = '-', count: nil)
  args = [first, last, true]
  args += ['COUNT', count] if count
  with_stream_at(key) do |stream|
    return stream.range(*args)
  end
end

#xtrim(key, count) ⇒ Object



42
43
44
45
46
# File 'lib/mock_redis/stream_methods.rb', line 42

def xtrim(key, count)
  with_stream_at(key) do |stream|
    stream.trim count
  end
end