?
本文檔使用 php中文網(wǎng)手冊 發(fā)布
KEYS pattern
自1.0.0起可用。
時間復(fù)雜度: O(N),其中N是數(shù)據(jù)庫中的鍵的數(shù)量,假設(shè)數(shù)據(jù)庫中的鍵名和給定模式的長度有限。
返回所有匹配的鍵pattern
。
雖然此操作的時間復(fù)雜度為O(N),但常數(shù)時間相當(dāng)短。例如,運行在入門級筆記本電腦上的 Redis 可以在40毫秒內(nèi)掃描一百萬個密鑰數(shù)據(jù)庫。
警告:將 KEYS 視為僅應(yīng)在生產(chǎn)環(huán)境中謹(jǐn)慎使用的命令。在對大型數(shù)據(jù)庫執(zhí)行它時可能會損壞性能。此命令用于調(diào)試和特殊操作,例如更改您的密鑰空間布局。請勿在常規(guī)應(yīng)用程序代碼中使用KEYS。如果您正在尋找一種方法在您的密鑰空間的子集中查找密鑰,請考慮使用 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
\
如果您想逐字匹配,請使用轉(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"