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

Function lookupStringForBitCommand

app/redis-6.2.6/src/bitops.c:480–493  ·  view source on GitHub ↗

This is an helper function for commands implementations that need to write * bits to a string object. The command creates or pad with zeroes the string * so that the 'maxbit' bit can be addressed. The object is finally * returned. Otherwise if the key holds a wrong type NULL is returned and * an error is sent to the client. */

Source from the content-addressed store, hash-verified

478 * returned. Otherwise if the key holds a wrong type NULL is returned and
479 * an error is sent to the client. */
480robj *lookupStringForBitCommand(client *c, uint64_t maxbit) {
481 size_t byte = maxbit >> 3;
482 robj *o = lookupKeyWrite(c->db,c->argv[1]);
483 if (checkType(c,o,OBJ_STRING)) return NULL;
484
485 if (o == NULL) {
486 o = createObject(OBJ_STRING,sdsnewlen(NULL, byte+1));
487 dbAdd(c->db,c->argv[1],o);
488 } else {
489 o = dbUnshareStringValue(c->db,c->argv[1],o);
490 o->ptr = sdsgrowzero(o->ptr,byte+1);
491 }
492 return o;
493}
494
495/* Return a pointer to the string object content, and stores its length
496 * in 'len'. The user is required to pass (likely stack allocated) buffer

Callers 2

setbitCommandFunction · 0.85
bitfieldGenericFunction · 0.85

Calls 7

lookupKeyWriteFunction · 0.85
checkTypeFunction · 0.85
createObjectFunction · 0.85
sdsnewlenFunction · 0.85
dbAddFunction · 0.85
dbUnshareStringValueFunction · 0.85
sdsgrowzeroFunction · 0.85

Tested by

no test coverage detected