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

Function rdbSaveObject

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

Save a Redis object. * Returns -1 on error, number of bytes written on success. */

Source from the content-addressed store, hash-verified

804/* Save a Redis object.
805 * Returns -1 on error, number of bytes written on success. */
806ssize_t rdbSaveObject(rio *rdb, robj *o, robj *key) {
807 ssize_t n = 0, nwritten = 0;
808
809 if (o->type == OBJ_STRING) {
810 /* Save a string value */
811 if ((n = rdbSaveStringObject(rdb,o)) == -1) return -1;
812 nwritten += n;
813 } else if (o->type == OBJ_LIST) {
814 /* Save a list value */
815 if (o->encoding == OBJ_ENCODING_QUICKLIST) {
816 quicklist *ql = o->ptr;
817 quicklistNode *node = ql->head;
818
819 if ((n = rdbSaveLen(rdb,ql->len)) == -1) return -1;
820 nwritten += n;
821
822 while(node) {
823 if (quicklistNodeIsCompressed(node)) {
824 void *data;
825 size_t compress_len = quicklistGetLzf(node, &data);
826 if ((n = rdbSaveLzfBlob(rdb,data,compress_len,node->sz)) == -1) return -1;
827 nwritten += n;
828 } else {
829 if ((n = rdbSaveRawString(rdb,node->zl,node->sz)) == -1) return -1;
830 nwritten += n;
831 }
832 node = node->next;
833 }
834 } else {
835 serverPanic("Unknown list encoding");
836 }
837 } else if (o->type == OBJ_SET) {
838 /* Save a set value */
839 if (o->encoding == OBJ_ENCODING_HT) {
840 dict *set = o->ptr;
841 dictIterator *di = dictGetIterator(set);
842 dictEntry *de;
843
844 if ((n = rdbSaveLen(rdb,dictSize(set))) == -1) {
845 dictReleaseIterator(di);
846 return -1;
847 }
848 nwritten += n;
849
850 while((de = dictNext(di)) != NULL) {
851 sds ele = dictGetKey(de);
852 if ((n = rdbSaveRawString(rdb,(unsigned char*)ele,sdslen(ele)))
853 == -1)
854 {
855 dictReleaseIterator(di);
856 return -1;
857 }
858 nwritten += n;
859 }
860 dictReleaseIterator(di);
861 } else if (o->encoding == OBJ_ENCODING_INTSET) {
862 size_t l = intsetBlobLen((intset*)o->ptr);
863

Callers 3

rdbSavedObjectLenFunction · 0.85
rdbSaveKeyValuePairFunction · 0.85
createDumpPayloadFunction · 0.85

Calls 15

rdbSaveStringObjectFunction · 0.85
rdbSaveLenFunction · 0.85
quicklistGetLzfFunction · 0.85
rdbSaveLzfBlobFunction · 0.85
rdbSaveRawStringFunction · 0.85
sdslenFunction · 0.85
intsetBlobLenFunction · 0.85
ziplistBlobLenFunction · 0.85
rdbSaveBinaryDoubleValueFunction · 0.85
raxSizeFunction · 0.85
raxStartFunction · 0.85
raxSeekFunction · 0.85

Tested by

no test coverage detected