Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Memory usage: CAP the stream #6

Merged
merged 3 commits into from
Sep 25, 2024
Merged

[FIX] Memory usage: CAP the stream #6

merged 3 commits into from
Sep 25, 2024

Conversation

garciaf
Copy link
Member

@garciaf garciaf commented Sep 25, 2024

Make sure we keep our stream in check using the maxlen option. According to the documentation. That is a possible solution for our memory usage issue.

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.

Screenshot 2024-09-25 at 10 12 31

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.
@garciaf garciaf changed the title [FIX] Memory usage CAO the stream [FIX] Memory usage: CAP the stream Sep 25, 2024
@garciaf garciaf merged commit e640dc3 into main Sep 25, 2024
1 check passed
@garciaf garciaf deleted the feature/cap-stream branch September 25, 2024 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants