<p>KEYS pattern</p><p>起始版本:1.0.0</p><p>时间复杂度:O(N) with N being the number of keys in the database, under the assumption that the key names in the database and the given pattern have limited length.</p><p>查找所有符合给定模式pattern(正则表达式)的 key 。</p><p>时间复杂度为O(N),N为数据库里面key的数量。</p><p>例如,Redis在一个有1百万个key的数据库里面执行一次查询需要的时间是40毫秒 。</p><p>警告: KEYS 的速度非常快,但在一个大的数据库中使用它仍然可能造成性能问题,如果你需要从一个数据集中查找特定的 KEYS, 你最好还是用 Redis 的集合结构 SETS 来代替。</p><p>支持的正则表达模式:</p><p>h?llo 匹配 hello, hallo 和 hxllo</p><p>h*llo 匹配 hllo 和 heeeello</p><p>h[ae]llo 匹配 hello 和 hallo, 但是不匹配 hillo</p><p>h[^e]llo 匹配 hallo, hbllo, … 但是不匹配 hello</p><p>h[a-b]llo 匹配 hallo 和 hbllo</p><p>如果你想取消字符的特殊匹配(正则表达式,可以在它的前面加\。</p><p>返回值</p><p>array-reply: 所有符合条件的key</p><p>例子</p><p>redis> MSET one 1 two 2 three 3 four 4</p><p>OK</p><p>redis> KEYS *o*</p><p>1) "four"</p><p>2) "one"</p><p>3) "two"</p><p>redis> KEYS t??</p><p>1) "two"</p><p>redis> KEYS *</p><p>1) "four"</p><p>2) "three"</p><p>3) "one"</p><p>4) "two"</p><p>redis></p>