?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
KEYS pattern
自1.0.0起可用。
時間復雜度: O(N),其中N是數(shù)據(jù)庫中的鍵的數(shù)量,假設數(shù)據(jù)庫中的鍵名和給定模式的長度有限。
返回所有匹配的鍵pattern
。
雖然此操作的時間復雜度為O(N),但常數(shù)時間相當短。例如,運行在入門級筆記本電腦上的 Redis 可以在40毫秒內掃描一百萬個密鑰數(shù)據(jù)庫。
警告:將 KEYS 視為僅應在生產環(huán)境中謹慎使用的命令。在對大型數(shù)據(jù)庫執(zhí)行它時可能會損壞性能。此命令用于調試和特殊操作,例如更改您的密鑰空間布局。請勿在常規(guī)應用程序代碼中使用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
\
如果您想逐字匹配,請使用轉義特殊字符。
陣列回復:密鑰匹配列表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"