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

Function findBigKeys

app/redis-6.2.6/src/redis-cli.c:7655–7788  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7653}
7654
7655static void findBigKeys(int memkeys, unsigned memkeys_samples) {
7656 unsigned long long sampled = 0, total_keys, totlen=0, *sizes=NULL, it=0;
7657 redisReply *reply, *keys;
7658 unsigned int arrsize=0, i;
7659 dictIterator *di;
7660 dictEntry *de;
7661 typeinfo **types = NULL;
7662 double pct;
7663
7664 dict *types_dict = dictCreate(&typeinfoDictType, NULL);
7665 typeinfo_add(types_dict, "string", &type_string);
7666 typeinfo_add(types_dict, "list", &type_list);
7667 typeinfo_add(types_dict, "set", &type_set);
7668 typeinfo_add(types_dict, "hash", &type_hash);
7669 typeinfo_add(types_dict, "zset", &type_zset);
7670 typeinfo_add(types_dict, "stream", &type_stream);
7671
7672 /* Total keys pre scanning */
7673 total_keys = getDbSize();
7674
7675 /* Status message */
7676 printf("\n# Scanning the entire keyspace to find biggest keys as well as\n");
7677 printf("# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec\n");
7678 printf("# per 100 SCAN commands (not usually needed).\n\n");
7679
7680 /* SCAN loop */
7681 do {
7682 /* Calculate approximate percentage completion */
7683 pct = 100 * (double)sampled/total_keys;
7684
7685 /* Grab some keys and point to the keys array */
7686 reply = sendScan(&it);
7687 keys = reply->element[1];
7688
7689 /* Reallocate our type and size array if we need to */
7690 if(keys->elements > arrsize) {
7691 types = zrealloc(types, sizeof(typeinfo*)*keys->elements);
7692 sizes = zrealloc(sizes, sizeof(unsigned long long)*keys->elements);
7693
7694 if(!types || !sizes) {
7695 fprintf(stderr, "Failed to allocate storage for keys!\n");
7696 exit(1);
7697 }
7698
7699 arrsize = keys->elements;
7700 }
7701
7702 /* Retrieve types and then sizes */
7703 getKeyTypes(types_dict, keys, types);
7704 getKeySizes(keys, types, sizes, memkeys, memkeys_samples);
7705
7706 /* Now update our stats */
7707 for(i=0;i<keys->elements;i++) {
7708 typeinfo *type = types[i];
7709 /* Skip keys that disappeared between SCAN and TYPE */
7710 if(!type)
7711 continue;
7712

Callers 1

mainFunction · 0.85

Calls 15

typeinfo_addFunction · 0.85
getDbSizeFunction · 0.85
sendScanFunction · 0.85
zreallocFunction · 0.85
getKeyTypesFunction · 0.85
getKeySizesFunction · 0.85
sdsfreeFunction · 0.85
sdscatreprFunction · 0.85
sdsemptyFunction · 0.85
freeReplyObjectFunction · 0.85
dictCreateFunction · 0.70
zfreeFunction · 0.70

Tested by

no test coverage detected