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

Function createObject

src/object.cpp:44–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42/* ===================== Creation and parsing of objects ==================== */
43
44robj *createObject(int type, void *ptr) {
45 size_t mvccExtraBytes = g_pserver->fActiveReplica ? sizeof(redisObjectExtended) : 0;
46 char *oB = (char*)zcalloc(sizeof(robj)+mvccExtraBytes, MALLOC_SHARED);
47 robj *o = reinterpret_cast<robj*>(oB + mvccExtraBytes);
48
49 new (o) redisObject;
50 o->type = type;
51 o->encoding = OBJ_ENCODING_RAW;
52 o->m_ptr = ptr;
53 o->setrefcount(1);
54 setMvccTstamp(o, OBJ_MVCC_INVALID);
55
56 /* Set the LRU to the current lruclock (minutes resolution), or
57 * alternatively the LFU counter. */
58 if (g_pserver->maxmemory_policy & MAXMEMORY_FLAG_LFU) {
59 o->lru = (LFUGetTimeInMinutes()<<8) | LFU_INIT_VAL;
60 } else {
61 o->lru = LRU_CLOCK();
62 }
63 return o;
64}
65
66/* Set a special refcount in the object to make it "shared":
67 * incrRefCount and decrRefCount() will test for this special refcount

Callers 15

sortCommandFunction · 0.85
hashTypeDupFunction · 0.85
rdbLoadIntegerObjectFunction · 0.85
rdbLoadLzfStringObjectFunction · 0.85
rdbLoadObjectFunction · 0.85
makeObjectSharedFunction · 0.85
createRawStringObjectFunction · 0.85
tryCreateRawStringObjectFunction · 0.85
dupStringObjectFunction · 0.85
createQuicklistObjectFunction · 0.85
createZiplistObjectFunction · 0.85

Calls 5

zcallocFunction · 0.85
setMvccTstampFunction · 0.85
LFUGetTimeInMinutesFunction · 0.85
LRU_CLOCKFunction · 0.85
setrefcountMethod · 0.80

Tested by

no test coverage detected