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
| 3699 | * - EBADF if the key is not opened for writing |
| 3700 | */ |
| 3701 | long 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 | * |
nothing calls this directly
no test coverage detected