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

Function lindexCommand

src/t_list.cpp:340–362  ·  view source on GitHub ↗

LINDEX */

Source from the content-addressed store, hash-verified

338
339/* LINDEX <key> <index> */
340void lindexCommand(client *c) {
341 robj_roptr o = lookupKeyReadOrReply(c,c->argv[1],shared.null[c->resp]);
342 if (o == nullptr || checkType(c,o,OBJ_LIST)) return;
343 long index;
344
345 if ((getLongFromObjectOrReply(c, c->argv[2], &index, NULL) != C_OK))
346 return;
347
348 if (o->encoding == OBJ_ENCODING_QUICKLIST) {
349 quicklistEntry entry;
350 if (quicklistIndex((quicklist*)ptrFromObj(o), index, &entry)) {
351 if (entry.value) {
352 addReplyBulkCBuffer(c, entry.value, entry.sz);
353 } else {
354 addReplyBulkLongLong(c, entry.longval);
355 }
356 } else {
357 addReplyNull(c);
358 }
359 } else {
360 serverPanic("Unknown list encoding");
361 }
362}
363
364/* LSET <key> <index> <element> */
365void lsetCommand(client *c) {

Callers

nothing calls this directly

Calls 8

lookupKeyReadOrReplyFunction · 0.85
checkTypeFunction · 0.85
getLongFromObjectOrReplyFunction · 0.85
quicklistIndexFunction · 0.85
ptrFromObjFunction · 0.85
addReplyBulkCBufferFunction · 0.85
addReplyBulkLongLongFunction · 0.85
addReplyNullFunction · 0.85

Tested by

no test coverage detected