?
This document uses PHP Chinese website manual Release
KEYS pattern
自1.0.0起可用。
時(shí)間復(fù)雜度: O(N),其中N是數(shù)據(jù)庫(kù)中的鍵的數(shù)量,假設(shè)數(shù)據(jù)庫(kù)中的鍵名和給定模式的長(zhǎng)度有限。
返回所有匹配的鍵pattern
。
雖然此操作的時(shí)間復(fù)雜度為O(N),但常數(shù)時(shí)間相當(dāng)短。例如,運(yùn)行在入門(mén)級(jí)筆記本電腦上的 Redis 可以在40毫秒內(nèi)掃描一百萬(wàn)個(gè)密鑰數(shù)據(jù)庫(kù)。
警告:將 KEYS 視為僅應(yīng)在生產(chǎn)環(huán)境中謹(jǐn)慎使用的命令。在對(duì)大型數(shù)據(jù)庫(kù)執(zhí)行它時(shí)可能會(huì)損壞性能。此命令用于調(diào)試和特殊操作,例如更改您的密鑰空間布局。請(qǐng)勿在常規(guī)應(yīng)用程序代碼中使用KEYS。如果您正在尋找一種方法在您的密鑰空間的子集中查找密鑰,請(qǐng)考慮使用 SCAN 或集合。
支持的全局樣式模式:
h?llo
matches hello
, hallo
and hxllo
h*llo
matches hllo
and heeeello
h[ae]llo
matches hello
and hallo,
but not hillo
h[^e]llo
matches hallo
, hbllo
, ... but not hello
h[a-b]llo
matches hallo
and hbllo
\
如果您想逐字匹配,請(qǐng)使用轉(zhuǎn)義特殊字符。
陣列回復(fù):密鑰匹配列表pattern
。
redis> MSET one 1 two 2 three 3 four 4 "OK"
redis> KEYS *o* 1) "one" 2) "four" 3) "two"
redis> KEYS t?? 1) "two"
redis> KEYS * 1) "three" 2) "one" 3) "four" 4) "two"