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

Function rdbGenericLoadStringObject

app/redis-6.2.6/src/rdb.c:508–560  ·  view source on GitHub ↗

Load a string object from an RDB file according to flags: * * RDB_LOAD_NONE (no flags): load an RDB object, unencoded. * RDB_LOAD_ENC: If the returned type is a Redis object, try to * encode it in a special way to be more memory * efficient. When this flag is passed the function * no longer guarantees that obj->ptr is an SDS string. * RDB_LOAD_PLAIN

Source from the content-addressed store, hash-verified

506 * On I/O error NULL is returned.
507 */
508void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) {
509 int encode = flags & RDB_LOAD_ENC;
510 int plain = flags & RDB_LOAD_PLAIN;
511 int sds = flags & RDB_LOAD_SDS;
512 int isencoded;
513 unsigned long long len;
514
515 len = rdbLoadLen(rdb,&isencoded);
516 if (len == RDB_LENERR) return NULL;
517
518 if (isencoded) {
519 switch(len) {
520 case RDB_ENC_INT8:
521 case RDB_ENC_INT16:
522 case RDB_ENC_INT32:
523 return rdbLoadIntegerObject(rdb,len,flags,lenptr);
524 case RDB_ENC_LZF:
525 return rdbLoadLzfStringObject(rdb,flags,lenptr);
526 default:
527 rdbReportCorruptRDB("Unknown RDB string encoding type %llu",len);
528 return NULL;
529 }
530 }
531
532 if (plain || sds) {
533 void *buf = plain ? ztrymalloc(len) : sdstrynewlen(SDS_NOINIT,len);
534 if (!buf) {
535 serverLog(server.loading? LL_WARNING: LL_VERBOSE, "rdbGenericLoadStringObject failed allocating %llu bytes", len);
536 return NULL;
537 }
538 if (lenptr) *lenptr = len;
539 if (len && rioRead(rdb,buf,len) == 0) {
540 if (plain)
541 zfree(buf);
542 else
543 sdsfree(buf);
544 return NULL;
545 }
546 return buf;
547 } else {
548 robj *o = encode ? tryCreateStringObject(SDS_NOINIT,len) :
549 tryCreateRawStringObject(SDS_NOINIT,len);
550 if (!o) {
551 serverLog(server.loading? LL_WARNING: LL_VERBOSE, "rdbGenericLoadStringObject failed allocating %llu bytes", len);
552 return NULL;
553 }
554 if (len && rioRead(rdb,o->ptr,len) == 0) {
555 decrRefCount(o);
556 return NULL;
557 }
558 return o;
559 }
560}
561
562robj *rdbLoadStringObject(rio *rdb) {
563 return rdbGenericLoadStringObject(rdb,RDB_LOAD_NONE,NULL);

Callers 6

rdbLoadStringObjectFunction · 0.85
rdbLoadCheckModuleValueFunction · 0.85
rdbLoadObjectFunction · 0.85
rdbLoadRioFunction · 0.85
moduleLoadStringFunction · 0.85

Calls 11

rdbLoadLenFunction · 0.85
rdbLoadIntegerObjectFunction · 0.85
rdbLoadLzfStringObjectFunction · 0.85
ztrymallocFunction · 0.85
sdstrynewlenFunction · 0.85
rioReadFunction · 0.85
sdsfreeFunction · 0.85
tryCreateStringObjectFunction · 0.85
tryCreateRawStringObjectFunction · 0.85
decrRefCountFunction · 0.85
zfreeFunction · 0.70

Tested by

no test coverage detected