MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / RM_StreamTrimByID

Function RM_StreamTrimByID

src/module.cpp:3819–3833  ·  view source on GitHub ↗

Trim a stream by ID, similar to XTRIM with MINID. * * - `key`: Key opened for writing. * - `flags`: A bitfield of * - `REDISMODULE_STREAM_TRIM_APPROX`: Trim less if it improves performance, * like XTRIM with `~`. * - `id`: The smallest stream ID to keep after trimming. * * Returns the number of entries deleted. On failure, a negative value is * returned and `errno` is set as follows

Source from the content-addressed store, hash-verified

3817 * - EBADF if the key is not opened for writing
3818 */
3819long long RM_StreamTrimByID(RedisModuleKey *key, int flags, RedisModuleStreamID *id) {
3820 if (!key || (flags & ~(REDISMODULE_STREAM_TRIM_APPROX)) || !id) {
3821 errno = EINVAL;
3822 return -1;
3823 } else if (!key->value || key->value->type != OBJ_STREAM) {
3824 errno = ENOTSUP;
3825 return -1;
3826 } else if (!(key->mode & REDISMODULE_WRITE)) {
3827 errno = EBADF;
3828 return -1;
3829 }
3830 int approx = flags & REDISMODULE_STREAM_TRIM_APPROX ? 1 : 0;
3831 streamID minid = {id->ms, id->seq};
3832 return streamTrimByID((stream *)ptrFromObj(key->value), minid, approx);
3833}
3834
3835/* --------------------------------------------------------------------------
3836 * ## Calling Redis commands from modules

Callers

nothing calls this directly

Calls 2

streamTrimByIDFunction · 0.85
ptrFromObjFunction · 0.85

Tested by

no test coverage detected