Skip to content

Commit e640dc3

Browse files
authored
[FIX] Memory usage: CAP the stream (#6)
* [FIX] Memory usage CAO the stream Make sure we keep our stream in check using the maxlen option. According to the documentation # Documentation https://redis.io/docs/latest/commands/xadd/ ## Capped streams XADD incorporates the same semantics as the XTRIM command - refer to its documentation page for more information. This allows adding new entries and keeping the stream's size in check with a single call to XADD, effectively capping the stream with an arbitrary threshold. Although exact trimming is possible and is the default, due to the internal representation of steams it is more efficient to add an entry and trim stream with XADD using almost exact trimming (the ~ argument). For example, calling XADD in the following form: ``` XADD mystream MAXLEN ~ 1000 * ... entry fields here ... ``` Will add a new entry but will also evict old entries so that the stream will contain only 1000 entries, or at most a few tens more. * formatting
1 parent 16e177a commit e640dc3

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
redis_stream (0.1.4)
4+
redis_stream (0.1.5)
55

66
GEM
77
remote: https://rubygems.org/

lib/redis_stream/publisher.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def initialize(stream_key)
1010

1111
def publish(name, data = {})
1212
data = {"name" => name, "json" => JSON.generate(data)}
13-
RedisStream.client.xadd(@stream_key, data)
13+
RedisStream.client.xadd(@stream_key, data, maxlen: 1000, approximate: true)
1414
end
1515
end
1616
end

lib/redis_stream/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module RedisStream
4-
VERSION = "0.1.4"
4+
VERSION = "0.1.5"
55
end

0 commit comments

Comments
 (0)