MCPcopy Create free account
hub / github.com/F-Stack/f-stack / RM_StreamTrimByLength

Function RM_StreamTrimByLength

app/redis-6.2.6/src/module.c:3701–3714  ·  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

3699 * - EBADF if the key is not opened for writing
3700 */
3701long long RM_StreamTrimByLength(RedisModuleKey *key, int flags, long long length) {
3702 if (!key || (flags & ~(REDISMODULE_STREAM_TRIM_APPROX)) || length < 0) {
3703 errno = EINVAL;
3704 return -1;
3705 } else if (!key->value || key->value->type != OBJ_STREAM) {
3706 errno = ENOTSUP;
3707 return -1;
3708 } else if (!(key->mode & REDISMODULE_WRITE)) {
3709 errno = EBADF;
3710 return -1;
3711 }
3712 int approx = flags & REDISMODULE_STREAM_TRIM_APPROX ? 1 : 0;
3713 return streamTrimByLength((stream *)key->value->ptr, length, approx);
3714}
3715
3716/* Trim a stream by ID, similar to XTRIM with MINID.
3717 *

Callers

nothing calls this directly

Calls 1

streamTrimByLengthFunction · 0.85

Tested by

no test coverage detected