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

Function xtrimCommand

app/redis-6.2.6/src/t_stream.c:3259–3292  ·  view source on GitHub ↗

General form: XTRIM [... options ...] * * List of options: * * Trim strategies: * * MAXLEN [~|=] -- Trim so that the stream will be capped at * the specified length. Use ~ before the * count in order to demand approximated trimming * (like XADD MAXLEN option). * MINID [~|=]

Source from the content-addressed store, hash-verified

3257 * Has meaning only if `~` was provided.
3258 */
3259void xtrimCommand(client *c) {
3260 robj *o;
3261
3262 /* Argument parsing. */
3263 streamAddTrimArgs parsed_args;
3264 if (streamParseAddOrTrimArgsOrReply(c, &parsed_args, 0) < 0)
3265 return; /* streamParseAddOrTrimArgsOrReply already replied. */
3266
3267 /* If the key does not exist, we are ok returning zero, that is, the
3268 * number of elements removed from the stream. */
3269 if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.czero)) == NULL
3270 || checkType(c,o,OBJ_STREAM)) return;
3271 stream *s = o->ptr;
3272
3273 /* Perform the trimming. */
3274 int64_t deleted = streamTrim(s, &parsed_args);
3275 if (deleted) {
3276 notifyKeyspaceEvent(NOTIFY_STREAM,"xtrim",c->argv[1],c->db->id);
3277 if (parsed_args.approx_trim) {
3278 /* In case our trimming was limited (by LIMIT or by ~) we must
3279 * re-write the relevant trim argument to make sure there will be
3280 * no inconsistencies in AOF loading or in the replica.
3281 * It's enough to check only args->approx because there is no
3282 * way LIMIT is given without the ~ option. */
3283 streamRewriteApproxSpecifier(c,parsed_args.trim_strategy_arg_idx-1);
3284 streamRewriteTrimArgument(c,s,parsed_args.trim_strategy,parsed_args.trim_strategy_arg_idx);
3285 }
3286
3287 /* Propagate the write. */
3288 signalModifiedKey(c, c->db,c->argv[1]);
3289 server.dirty += deleted;
3290 }
3291 addReplyLongLong(c,deleted);
3292}
3293
3294/* Helper function for xinfoCommand.
3295 * Handles the variants of XINFO STREAM */

Callers

nothing calls this directly

Calls 9

lookupKeyWriteOrReplyFunction · 0.85
checkTypeFunction · 0.85
streamTrimFunction · 0.85
notifyKeyspaceEventFunction · 0.85
signalModifiedKeyFunction · 0.85
addReplyLongLongFunction · 0.85

Tested by

no test coverage detected