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

Function getbitCommand

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

GETBIT key offset */

Source from the content-addressed store, hash-verified

564
565/* GETBIT key offset */
566void getbitCommand(client *c) {
567 robj *o;
568 char llbuf[32];
569 uint64_t bitoffset;
570 size_t byte, bit;
571 size_t bitval = 0;
572
573 if (getBitOffsetFromArgument(c,c->argv[2],&bitoffset,0,0) != C_OK)
574 return;
575
576 if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||
577 checkType(c,o,OBJ_STRING)) return;
578
579 byte = bitoffset >> 3;
580 bit = 7 - (bitoffset & 0x7);
581 if (sdsEncodedObject(o)) {
582 if (byte < sdslen(o->ptr))
583 bitval = ((uint8_t*)o->ptr)[byte] & (1 << bit);
584 } else {
585 if (byte < (size_t)ll2string(llbuf,sizeof(llbuf),(long)o->ptr))
586 bitval = llbuf[byte] & (1 << bit);
587 }
588
589 addReply(c, bitval ? shared.cone : shared.czero);
590}
591
592/* BITOP op_name target_key src_key1 src_key2 src_key3 ... src_keyN */
593void bitopCommand(client *c) {

Callers

nothing calls this directly

Calls 6

getBitOffsetFromArgumentFunction · 0.85
lookupKeyReadOrReplyFunction · 0.85
checkTypeFunction · 0.85
sdslenFunction · 0.85
ll2stringFunction · 0.85
addReplyFunction · 0.85

Tested by

no test coverage detected