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

Function nhsetCommand

src/t_nhash.cpp:338–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

336}
337
338void nhsetCommand(client *c) {
339 if (c->argc < 3)
340 throw shared.syntaxerr;
341
342 robj *val = c->argv[2];
343 if (c->argc > 3) {
344 // Its a list, we'll store as a ziplist
345 val = createZiplistObject();
346 for (int iarg = 2; iarg < c->argc; ++iarg) {
347 sds arg = (sds)szFromObj(c->argv[iarg]);
348 val->m_ptr = ziplistPush((unsigned char*)ptrFromObj(val), (unsigned char*)arg, sdslen(arg), ZIPLIST_TAIL);
349 }
350 }
351
352 try {
353 if (setWithKey(c->db, c->argv[1], val, true)) {
354 addReplyLongLong(c, 1); // we replaced a value
355 } else {
356 addReplyLongLong(c, 0); // we added a new value
357 }
358 } catch (...) {
359 if (val != c->argv[2])
360 decrRefCount(val);
361 throw;
362 }
363 if (val != c->argv[2])
364 decrRefCount(val);
365}
366
367void nhgetCommand(client *c) {
368 if (c->argc != 2 && c->argc != 3)

Callers

nothing calls this directly

Calls 8

createZiplistObjectFunction · 0.85
szFromObjFunction · 0.85
ziplistPushFunction · 0.85
ptrFromObjFunction · 0.85
sdslenFunction · 0.85
setWithKeyFunction · 0.85
addReplyLongLongFunction · 0.85
decrRefCountFunction · 0.85

Tested by

no test coverage detected