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

Function rdbSaveRawString

src/rdb.cpp:441–471  ·  view source on GitHub ↗

Save a string object as [len][data] on disk. If the object is a string * representation of an integer value we try to save it in a special form */

Source from the content-addressed store, hash-verified

439/* Save a string object as [len][data] on disk. If the object is a string
440 * representation of an integer value we try to save it in a special form */
441ssize_t rdbSaveRawString(rio *rdb, const unsigned char *s, size_t len) {
442 int enclen;
443 ssize_t n, nwritten = 0;
444
445 /* Try integer encoding */
446 if (len <= 11) {
447 unsigned char buf[5];
448 if ((enclen = rdbTryIntegerEncoding((char*)s,len,buf)) > 0) {
449 if (rdbWriteRaw(rdb,buf,enclen) == -1) return -1;
450 return enclen;
451 }
452 }
453
454 /* Try LZF compression - under 20 bytes it's unable to compress even
455 * aaaaaaaaaaaaaaaaaa so skip it */
456 if (g_pserver->rdb_compression && len > 20) {
457 n = rdbSaveLzfStringObject(rdb,(const unsigned char*)s,len);
458 if (n == -1) return -1;
459 if (n > 0) return n;
460 /* Return value of 0 means data can't be compressed, save the old way */
461 }
462
463 /* Store verbatim */
464 if ((n = rdbSaveLen(rdb,len)) == -1) return -1;
465 nwritten += n;
466 if (len > 0) {
467 if (rdbWriteRaw(rdb,(unsigned char*)s,len) == -1) return -1;
468 nwritten += len;
469 }
470 return nwritten;
471}
472
473/* Save a long long value as either an encoded string or a string. */
474ssize_t rdbSaveLongLongAsStringObject(rio *rdb, long long value) {

Callers 5

rdbSaveStringObjectFunction · 0.85
rdbSaveStreamConsumersFunction · 0.85
rdbSaveObjectFunction · 0.85
rdbSaveAuxFieldFunction · 0.85
RM_SaveStringBufferFunction · 0.85

Calls 4

rdbTryIntegerEncodingFunction · 0.85
rdbWriteRawFunction · 0.85
rdbSaveLzfStringObjectFunction · 0.85
rdbSaveLenFunction · 0.85

Tested by

no test coverage detected