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

Function xsetidCommand

src/t_stream.cpp:2509–2534  ·  view source on GitHub ↗

XSETID * * Set the internal "last ID" of a stream. */

Source from the content-addressed store, hash-verified

2507 *
2508 * Set the internal "last ID" of a stream. */
2509void xsetidCommand(client *c) {
2510 robj *o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr);
2511 if (o == NULL || checkType(c,o,OBJ_STREAM)) return;
2512
2513 stream *s = (stream*)ptrFromObj(o);
2514 streamID id;
2515 if (streamParseStrictIDOrReply(c,c->argv[2],&id,0) != C_OK) return;
2516
2517 /* If the stream has at least one item, we want to check that the user
2518 * is setting a last ID that is equal or greater than the current top
2519 * item, otherwise the fundamental ID monotonicity assumption is violated. */
2520 if (s->length > 0) {
2521 streamID maxid;
2522 streamLastValidID(s,&maxid);
2523
2524 if (streamCompareID(&id,&maxid) < 0) {
2525 addReplyError(c,"The ID specified in XSETID is smaller than the "
2526 "target stream top item");
2527 return;
2528 }
2529 }
2530 s->last_id = id;
2531 addReply(c,shared.ok);
2532 g_pserver->dirty++;
2533 notifyKeyspaceEvent(NOTIFY_STREAM,"xsetid",c->argv[1],c->db->id);
2534}
2535
2536/* XACK <key> <group> <id> <id> ... <id>
2537 *

Callers

nothing calls this directly

Calls 9

lookupKeyWriteOrReplyFunction · 0.85
checkTypeFunction · 0.85
ptrFromObjFunction · 0.85
streamLastValidIDFunction · 0.85
streamCompareIDFunction · 0.85
addReplyErrorFunction · 0.85
addReplyFunction · 0.85
notifyKeyspaceEventFunction · 0.85

Tested by

no test coverage detected