{"id":3061,"date":"2017-12-27T16:01:45","date_gmt":"2017-12-27T14:01:45","guid":{"rendered":"http:\/\/supportex.net\/blog\/?p=3061"},"modified":"2019-05-10T12:30:21","modified_gmt":"2019-05-10T10:30:21","slug":"redis-sort-keys-size","status":"publish","type":"post","link":"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/","title":{"rendered":"Redis: sort keys by size"},"content":{"rendered":"<p>There are multiple ways to figure out what take so much memory of your Redis instance. The simplest and quickest way is the following:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\"> redis-cli --bigkeys<\/code><\/p>\n<p>But for some cases it&#8217;s not enough. Then you can <a href=\"https:\/\/github.com\/gamenet\/redis-memory-analyzer\">Redis Memory analyzer<\/a> (requires Python 3.4). It does provide a lot of useful insights but didn&#8217;t help me either. So here&#8217;s a way which seems to be optimal in case you need to sort keys by used memory. This way needs\u00a0<a href=\"https:\/\/github.com\/sripathikrishnan\/redis-rdb-tools\">redis-rdb-tools<\/a> installed:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">pip install rdbtools<\/code><\/p>\n<p>then run:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">rdb -c memory \/var\/lib\/redis\/dump.rdb -f memory.txt<\/code><\/p>\n<p>rdb will go through the whole database and at end you will get all keys used memory output file. Once you have it won&#8217;t take one more minute to complete the task:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">OUT=.\/memory.csv\n\n{ echo -n \"TOTAL \"\ncat memory.csv | awk -F ',' '{sum += $4} END {print sum\/1024\/1024}' ;\n\nfor k in $( awk -F ',' '{print $3}' $OUT | awk -F ':' '{print $1}' | sort | uniq -c | sort -rnk1 | head -n 10 | awk '{print $2}' ) ; do\n echo -n \"$k \"\n grep $k memory.csv | awk -F ',' '{sum += $4} END {print sum\/1024\/1024}'\n\ndone ;} | sort -rnk2 | column -t\n[root@d1 ~]# \/usr\/local\/sbin\/redis_memory_report.sh\nTOTAL   1027.42\nbosons  291.925\nleptons 238.798\nquarks  170.58\n[root@d1 ~]#<\/pre>\n<p>There might be some smarter ways to get this but this one did the trick for me.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are multiple ways to figure out what take so much memory of your Redis instance. The simplest and quickest way is the following: redis-cli &#8211;bigkeys But for some cases it&#8217;s not enough. Then you can Redis Memory analyzer (requires Python 3.4). It does provide a lot of useful insights but didn&#8217;t help me either.&hellip; <\/p>\n<div class=\"readmore-wrapper\"><a href=\"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/\" class=\"more-link\">Read <\/a><\/div>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[152],"tags":[233],"class_list":["post-3061","post","type-post","status-publish","format-standard","hentry","category-linux","tag-redis-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Redis: sort keys by size &#8211; Supportex.NET blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Redis: sort keys by size &#8211; Supportex.NET blog\" \/>\n<meta property=\"og:description\" content=\"There are multiple ways to figure out what take so much memory of your Redis instance. The simplest and quickest way is the following: redis-cli --bigkeys But for some cases it&#8217;s not enough. Then you can Redis Memory analyzer (requires Python 3.4). It does provide a lot of useful insights but didn&#8217;t help me either.&hellip; Read\" \/>\n<meta property=\"og:url\" content=\"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/\" \/>\n<meta property=\"og:site_name\" content=\"Supportex.NET blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-27T14:01:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-05-10T10:30:21+00:00\" \/>\n<meta name=\"author\" content=\"Oleksii Tykhonov\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oleksii Tykhonov\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/\"},\"author\":{\"name\":\"Oleksii Tykhonov\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\"},\"headline\":\"Redis: sort keys by size\",\"datePublished\":\"2017-12-27T14:01:45+00:00\",\"dateModified\":\"2019-05-10T10:30:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/\"},\"wordCount\":136,\"commentCount\":0,\"keywords\":[\"redis\"],\"articleSection\":[\"linux\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/\",\"url\":\"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/\",\"name\":\"Redis: sort keys by size &#8211; Supportex.NET blog\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\"},\"datePublished\":\"2017-12-27T14:01:45+00:00\",\"dateModified\":\"2019-05-10T10:30:21+00:00\",\"author\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\"},\"breadcrumb\":{\"@id\":\"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/supportex.net\/blog\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Redis: sort keys by size\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\",\"url\":\"https:\/\/supportex.net\/blog\/en\/\",\"name\":\"Supportex.NET blog\",\"description\":\"Server and network management company\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\",\"name\":\"Oleksii Tykhonov\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g\",\"caption\":\"Oleksii Tykhonov\"},\"url\":\"https:\/\/supportex.net\/blog\/author\/oleksiitykhonov\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Redis: sort keys by size &#8211; Supportex.NET blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/","og_locale":"en_US","og_type":"article","og_title":"Redis: sort keys by size &#8211; Supportex.NET blog","og_description":"There are multiple ways to figure out what take so much memory of your Redis instance. The simplest and quickest way is the following: redis-cli --bigkeys But for some cases it&#8217;s not enough. Then you can Redis Memory analyzer (requires Python 3.4). It does provide a lot of useful insights but didn&#8217;t help me either.&hellip; Read","og_url":"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/","og_site_name":"Supportex.NET blog","article_published_time":"2017-12-27T14:01:45+00:00","article_modified_time":"2019-05-10T10:30:21+00:00","author":"Oleksii Tykhonov","twitter_misc":{"Written by":"Oleksii Tykhonov","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/#article","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/"},"author":{"name":"Oleksii Tykhonov","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251"},"headline":"Redis: sort keys by size","datePublished":"2017-12-27T14:01:45+00:00","dateModified":"2019-05-10T10:30:21+00:00","mainEntityOfPage":{"@id":"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/"},"wordCount":136,"commentCount":0,"keywords":["redis"],"articleSection":["linux"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/","url":"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/","name":"Redis: sort keys by size &#8211; Supportex.NET blog","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/en\/#website"},"datePublished":"2017-12-27T14:01:45+00:00","dateModified":"2019-05-10T10:30:21+00:00","author":{"@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251"},"breadcrumb":{"@id":"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/supportex.net\/blog\/2017\/12\/redis-sort-keys-size\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/supportex.net\/blog\/en\/"},{"@type":"ListItem","position":2,"name":"Redis: sort keys by size"}]},{"@type":"WebSite","@id":"https:\/\/supportex.net\/blog\/en\/#website","url":"https:\/\/supportex.net\/blog\/en\/","name":"Supportex.NET blog","description":"Server and network management company","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251","name":"Oleksii Tykhonov","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g","caption":"Oleksii Tykhonov"},"url":"https:\/\/supportex.net\/blog\/author\/oleksiitykhonov\/"}]}},"_links":{"self":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/3061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/comments?post=3061"}],"version-history":[{"count":6,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/3061\/revisions"}],"predecessor-version":[{"id":3110,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/3061\/revisions\/3110"}],"wp:attachment":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/media?parent=3061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/categories?post=3061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/tags?post=3061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}