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

Function lsetCommand

app/redis-6.2.6/src/t_list.c:365–394  ·  view source on GitHub ↗

LSET */

Source from the content-addressed store, hash-verified

363
364/* LSET <key> <index> <element> */
365void lsetCommand(client *c) {
366 robj *o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr);
367 if (o == NULL || checkType(c,o,OBJ_LIST)) return;
368 long index;
369 robj *value = c->argv[3];
370
371 if (sdslen(value->ptr) > LIST_MAX_ITEM_SIZE) {
372 addReplyError(c, "Element too large");
373 return;
374 }
375
376 if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != C_OK))
377 return;
378
379 if (o->encoding == OBJ_ENCODING_QUICKLIST) {
380 quicklist *ql = o->ptr;
381 int replaced = quicklistReplaceAtIndex(ql, index,
382 value->ptr, sdslen(value->ptr));
383 if (!replaced) {
384 addReplyErrorObject(c,shared.outofrangeerr);
385 } else {
386 addReply(c,shared.ok);
387 signalModifiedKey(c,c->db,c->argv[1]);
388 notifyKeyspaceEvent(NOTIFY_LIST,"lset",c->argv[1],c->db->id);
389 server.dirty++;
390 }
391 } else {
392 serverPanic("Unknown list encoding");
393 }
394}
395
396/* A helper for replying with a list's range between the inclusive start and end
397 * indexes as multi-bulk, with support for negative indexes. Note that start

Callers

nothing calls this directly

Calls 10

lookupKeyWriteOrReplyFunction · 0.85
checkTypeFunction · 0.85
sdslenFunction · 0.85
addReplyErrorFunction · 0.85
getLongFromObjectOrReplyFunction · 0.85
quicklistReplaceAtIndexFunction · 0.85
addReplyErrorObjectFunction · 0.85
addReplyFunction · 0.85
signalModifiedKeyFunction · 0.85
notifyKeyspaceEventFunction · 0.85

Tested by

no test coverage detected