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

Function rewriteSetObject

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

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

Source from the content-addressed store, hash-verified

1035/* Emit the commands needed to rebuild a set object.
1036 * The function returns 0 on error, 1 on success. */
1037int rewriteSetObject(rio *r, robj *key, robj *o) {
1038 long long count = 0, items = setTypeSize(o);
1039
1040 if (o->encoding == OBJ_ENCODING_INTSET) {
1041 int ii = 0;
1042 int64_t llval;
1043
1044 while(intsetGet(o->ptr,ii++,&llval)) {
1045 if (count == 0) {
1046 int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ?
1047 AOF_REWRITE_ITEMS_PER_CMD : items;
1048
1049 if (!rioWriteBulkCount(r,'*',2+cmd_items) ||
1050 !rioWriteBulkString(r,"SADD",4) ||
1051 !rioWriteBulkObject(r,key))
1052 {
1053 return 0;
1054 }
1055 }
1056 if (!rioWriteBulkLongLong(r,llval)) return 0;
1057 if (++count == AOF_REWRITE_ITEMS_PER_CMD) count = 0;
1058 items--;
1059 }
1060 } else if (o->encoding == OBJ_ENCODING_HT) {
1061 dictIterator *di = dictGetIterator(o->ptr);
1062 dictEntry *de;
1063
1064 while((de = dictNext(di)) != NULL) {
1065 sds ele = dictGetKey(de);
1066 if (count == 0) {
1067 int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ?
1068 AOF_REWRITE_ITEMS_PER_CMD : items;
1069
1070 if (!rioWriteBulkCount(r,'*',2+cmd_items) ||
1071 !rioWriteBulkString(r,"SADD",4) ||
1072 !rioWriteBulkObject(r,key))
1073 {
1074 dictReleaseIterator(di);
1075 return 0;
1076 }
1077 }
1078 if (!rioWriteBulkString(r,ele,sdslen(ele))) {
1079 dictReleaseIterator(di);
1080 return 0;
1081 }
1082 if (++count == AOF_REWRITE_ITEMS_PER_CMD) count = 0;
1083 items--;
1084 }
1085 dictReleaseIterator(di);
1086 } else {
1087 serverPanic("Unknown set encoding");
1088 }
1089 return 1;
1090}
1091
1092/* Emit the commands needed to rebuild a sorted set object.
1093 * The function returns 0 on error, 1 on success. */

Callers 1

rewriteAppendOnlyFileRioFunction · 0.85

Calls 10

setTypeSizeFunction · 0.85
intsetGetFunction · 0.85
rioWriteBulkCountFunction · 0.85
rioWriteBulkStringFunction · 0.85
rioWriteBulkObjectFunction · 0.85
rioWriteBulkLongLongFunction · 0.85
sdslenFunction · 0.85
dictGetIteratorFunction · 0.70
dictNextFunction · 0.70
dictReleaseIteratorFunction · 0.70

Tested by

no test coverage detected