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

Function xorObjectDigest

app/redis-6.2.6/src/debug.c:136–265  ·  view source on GitHub ↗

This function computes the digest of a data structure stored in the * object 'o'. It is the core of the DEBUG DIGEST command: when taking the * digest of a whole dataset, we take the digest of the key and the value * pair, and xor all those together. * * Note that this function does not reset the initial 'digest' passed, it * will continue mixing this object digest to anything that was alrea

Source from the content-addressed store, hash-verified

134 * will continue mixing this object digest to anything that was already
135 * present. */
136void xorObjectDigest(redisDb *db, robj *keyobj, unsigned char *digest, robj *o) {
137 uint32_t aux = htonl(o->type);
138 mixDigest(digest,&aux,sizeof(aux));
139 long long expiretime = getExpire(db,keyobj);
140 char buf[128];
141
142 /* Save the key and associated value */
143 if (o->type == OBJ_STRING) {
144 mixStringObjectDigest(digest,o);
145 } else if (o->type == OBJ_LIST) {
146 listTypeIterator *li = listTypeInitIterator(o,0,LIST_TAIL);
147 listTypeEntry entry;
148 while(listTypeNext(li,&entry)) {
149 robj *eleobj = listTypeGet(&entry);
150 mixStringObjectDigest(digest,eleobj);
151 decrRefCount(eleobj);
152 }
153 listTypeReleaseIterator(li);
154 } else if (o->type == OBJ_SET) {
155 setTypeIterator *si = setTypeInitIterator(o);
156 sds sdsele;
157 while((sdsele = setTypeNextObject(si)) != NULL) {
158 xorDigest(digest,sdsele,sdslen(sdsele));
159 sdsfree(sdsele);
160 }
161 setTypeReleaseIterator(si);
162 } else if (o->type == OBJ_ZSET) {
163 unsigned char eledigest[20];
164
165 if (o->encoding == OBJ_ENCODING_ZIPLIST) {
166 unsigned char *zl = o->ptr;
167 unsigned char *eptr, *sptr;
168 unsigned char *vstr;
169 unsigned int vlen;
170 long long vll;
171 double score;
172
173 eptr = ziplistIndex(zl,0);
174 serverAssert(eptr != NULL);
175 sptr = ziplistNext(zl,eptr);
176 serverAssert(sptr != NULL);
177
178 while (eptr != NULL) {
179 serverAssert(ziplistGet(eptr,&vstr,&vlen,&vll));
180 score = zzlGetScore(sptr);
181
182 memset(eledigest,0,20);
183 if (vstr != NULL) {
184 mixDigest(eledigest,vstr,vlen);
185 } else {
186 ll2string(buf,sizeof(buf),vll);
187 mixDigest(eledigest,buf,strlen(buf));
188 }
189
190 snprintf(buf,sizeof(buf),"%.17g",score);
191 mixDigest(eledigest,buf,strlen(buf));
192 xorDigest(digest,eledigest,20);
193 zzlNext(zl,&eptr,&sptr);

Callers 2

computeDatasetDigestFunction · 0.85
debugCommandFunction · 0.85

Calls 15

mixDigestFunction · 0.85
getExpireFunction · 0.85
mixStringObjectDigestFunction · 0.85
listTypeInitIteratorFunction · 0.85
listTypeNextFunction · 0.85
listTypeGetFunction · 0.85
decrRefCountFunction · 0.85
listTypeReleaseIteratorFunction · 0.85
setTypeInitIteratorFunction · 0.85
setTypeNextObjectFunction · 0.85
xorDigestFunction · 0.85
sdslenFunction · 0.85

Tested by

no test coverage detected