<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <link type="text/css" rel="stylesheet" href="style.css" /> </head> <body> <div id="page"> <div id='header'> <a href="index.html"> <img style="border:none" alt="Redis Documentation" src="redis.png"> </a> </div> <div id="pagecontent"> <div class="index"> <!-- This is a (PRE) block. Make sure it's left aligned or your toc title will be off. --> <b>KeysCommand: Contents</b><br> <a href="#KEYS _pattern_">KEYS _pattern_</a><br> <a href="#Return value">Return value</a> </div> <h1 class="wikiname">KeysCommand</h1> <div class="summary"> </div> <div class="narrow"> #sidebar <a href="GenericCommandsSidebar.html">GenericCommandsSidebar</a><h1><a name="KEYS _pattern_">KEYS _pattern_</a></h1> <i>Time complexity: O(n) (with n being the number of keys in the DB, and assuming keys and pattern of limited length)</i><blockquote>Returns all the keys matching the glob-style <i>pattern</i> asspace separated strings. For example if you have in thedatabase the keys "foo" and "foobar" the command "KEYS foo<code name="code" class="python">*</code>"will return "foo foobar".</blockquote> <blockquote>Note that while the time complexity for this operation is O(n)the constant times are pretty low. For example Redis runningon an entry level laptop can scan a 1 million keys databasein 40 milliseconds. <b>Still it's better to consider this one of <blockquote>the slow commands that may ruin the DB performance if not usedwith care*.</blockquote> <blockquote>In other words this command is intended only for debugging and *special* operations like creating a script to change the DB schema. Don't use it in your normal code. Use Redis <a href="Sets.html">Sets</a> in order to group together a subset of objects.</blockquote> Glob style patterns examples: <blockquote>* h?llo will match hello hallo hhllo* h*llo will match hllo heeeello* h<code name="code" class="python">[</code>ae<code name="code" class="python">]</code>llo will match hello and hallo, but not hillo</blockquote>Use \ to escape special chars if you want to match them verbatim.<h2><a name="Return value">Return value</a></h2> <a href="ReplyTypes.html">Multi bulk reply</a></b></blockquote> </div> </div> </div> </body> </html>