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

Function RM_StreamTrimByLength

src/module.cpp:3789–3802  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

3787 * - EBADF if the key is not opened for writing
3788 */
3789long long RM_StreamTrimByLength(RedisModuleKey *key, int flags, long long length) {
3790 if (!key || (flags & ~(REDISMODULE_STREAM_TRIM_APPROX)) || length < 0) {
3791 errno = EINVAL;
3792 return -1;
3793 } else if (!key->value || key->value->type != OBJ_STREAM) {
3794 errno = ENOTSUP;
3795 return -1;
3796 } else if (!(key->mode & REDISMODULE_WRITE)) {
3797 errno = EBADF;
3798 return -1;
3799 }
3800 int approx = flags & REDISMODULE_STREAM_TRIM_APPROX ? 1 : 0;
3801 return streamTrimByLength((stream *)ptrFromObj(key->value), length, approx);
3802}
3803
3804/* Trim a stream by ID, similar to XTRIM with MINID.
3805 *

Callers

nothing calls this directly

Calls 2

streamTrimByLengthFunction · 0.85
ptrFromObjFunction · 0.85

Tested by

no test coverage detected