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

Function rewriteListObject

app/redis-6.2.6/src/aof.c:993–1033  ·  view source on GitHub ↗

Emit the commands needed to rebuild a list object. * The function returns 0 on error, 1 on success. */

Source from the content-addressed store, hash-verified

991/* Emit the commands needed to rebuild a list object.
992 * The function returns 0 on error, 1 on success. */
993int rewriteListObject(rio *r, robj *key, robj *o) {
994 long long count = 0, items = listTypeLength(o);
995
996 if (o->encoding == OBJ_ENCODING_QUICKLIST) {
997 quicklist *list = o->ptr;
998 quicklistIter *li = quicklistGetIterator(list, AL_START_HEAD);
999 quicklistEntry entry;
1000
1001 while (quicklistNext(li,&entry)) {
1002 if (count == 0) {
1003 int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ?
1004 AOF_REWRITE_ITEMS_PER_CMD : items;
1005 if (!rioWriteBulkCount(r,'*',2+cmd_items) ||
1006 !rioWriteBulkString(r,"RPUSH",5) ||
1007 !rioWriteBulkObject(r,key))
1008 {
1009 quicklistReleaseIterator(li);
1010 return 0;
1011 }
1012 }
1013
1014 if (entry.value) {
1015 if (!rioWriteBulkString(r,(char*)entry.value,entry.sz)) {
1016 quicklistReleaseIterator(li);
1017 return 0;
1018 }
1019 } else {
1020 if (!rioWriteBulkLongLong(r,entry.longval)) {
1021 quicklistReleaseIterator(li);
1022 return 0;
1023 }
1024 }
1025 if (++count == AOF_REWRITE_ITEMS_PER_CMD) count = 0;
1026 items--;
1027 }
1028 quicklistReleaseIterator(li);
1029 } else {
1030 serverPanic("Unknown list encoding");
1031 }
1032 return 1;
1033}
1034
1035/* Emit the commands needed to rebuild a set object.
1036 * The function returns 0 on error, 1 on success. */

Callers 1

rewriteAppendOnlyFileRioFunction · 0.85

Calls 8

listTypeLengthFunction · 0.85
quicklistGetIteratorFunction · 0.85
quicklistNextFunction · 0.85
rioWriteBulkCountFunction · 0.85
rioWriteBulkStringFunction · 0.85
rioWriteBulkObjectFunction · 0.85
quicklistReleaseIteratorFunction · 0.85
rioWriteBulkLongLongFunction · 0.85

Tested by

no test coverage detected