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

Function xdelCommand

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

XDEL [ ... ] * * Removes the specified entries from the stream. Returns the number * of items actually deleted, that may be different from the number * of IDs passed in case certain IDs do not exist. */

Source from the content-addressed store, hash-verified

3198 * of items actually deleted, that may be different from the number
3199 * of IDs passed in case certain IDs do not exist. */
3200void xdelCommand(client *c) {
3201 robj *o;
3202
3203 if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.czero)) == NULL
3204 || checkType(c,o,OBJ_STREAM)) return;
3205 stream *s = o->ptr;
3206
3207 /* We need to sanity check the IDs passed to start. Even if not
3208 * a big issue, it is not great that the command is only partially
3209 * executed because at some point an invalid ID is parsed. */
3210 streamID static_ids[STREAMID_STATIC_VECTOR_LEN];
3211 streamID *ids = static_ids;
3212 int id_count = c->argc-2;
3213 if (id_count > STREAMID_STATIC_VECTOR_LEN)
3214 ids = zmalloc(sizeof(streamID)*id_count);
3215 for (int j = 2; j < c->argc; j++) {
3216 if (streamParseStrictIDOrReply(c,c->argv[j],&ids[j-2],0) != C_OK) goto cleanup;
3217 }
3218
3219 /* Actually apply the command. */
3220 int deleted = 0;
3221 for (int j = 2; j < c->argc; j++) {
3222 deleted += streamDeleteItem(s,&ids[j-2]);
3223 }
3224
3225 /* Propagate the write if needed. */
3226 if (deleted) {
3227 signalModifiedKey(c,c->db,c->argv[1]);
3228 notifyKeyspaceEvent(NOTIFY_STREAM,"xdel",c->argv[1],c->db->id);
3229 server.dirty += deleted;
3230 }
3231 addReplyLongLong(c,deleted);
3232cleanup:
3233 if (ids != static_ids) zfree(ids);
3234}
3235
3236/* General form: XTRIM <key> [... options ...]
3237 *

Callers

nothing calls this directly

Calls 9

lookupKeyWriteOrReplyFunction · 0.85
checkTypeFunction · 0.85
zmallocFunction · 0.85
streamDeleteItemFunction · 0.85
signalModifiedKeyFunction · 0.85
notifyKeyspaceEventFunction · 0.85
addReplyLongLongFunction · 0.85
zfreeFunction · 0.70

Tested by

no test coverage detected