This module provides predicates for interacting with Redis streams
using the XTRIM command. The xtrim_using_entry_id/4 predicate trims
a Redis stream based on a specified entry ID and a window of time,
while the xtrim_window_minid/3 predicate calculates the minimum ID
for trimming based on the provided entry ID and window size.
The default window size for trimming can be configured using the
window setting. By default, it is set to 5 seconds, but it can be
changed to any valid number of seconds.
Example Usage
Trim a Redis stream using a specific entry ID and window size:
?- xtrim_using_entry_id(Redis, Key, Id, [window(10)]).
- author
- - Roy Ratcliffe
- version
- - 1.0
- license
- - MIT
- xtrim_using_entry_id(+Redis, +Key, +Id, +Options) is det
- Trim the Redis stream identified by Key to remove entries older than
the specified Id as the upper bound and a window of time defined by
the window/1 option. The Id is expected to be in the format
"Millis-Sequence", where Millis is the timestamp in milliseconds.
The window size can be specified in Options, and if not provided,
the default window size from the window setting will be used.
- Arguments:
-
| Redis | - The Redis connection. |
| Key | - The Redis stream key to trim. |
| Id | - The ID of the entry to use as the minimum for trimming. |
| Options | - A list of options for trimming, including the window size. |
- xtrim_window_minid(+Id, -MinId, +Options) is det
- Calculate the minimum ID for trimming based on the provided entry ID
and the window/1 option. The MinId is calculated by subtracting
the window size (in seconds) from the timestamp part of the
provided Id. The resulting MinId is formatted as "Millis-0" to be
used for trimming the Redis stream.
- Arguments:
-
| Id | - The ID of the entry to use as the minimum for trimming. |
| MinId | - The calculated minimum ID for trimming, formatted as "Millis-0". |
| Options | - A list of options for trimming, including the window size. |