direktori cari
Cluster cluster addslots(集群 槽位) cluster count failure reports(集群计数失败报告) cluster countkeysinslot cluster delslots cluster failover cluster forget cluster getkeysinslot cluster info cluster keyslot(集群键槽) cluster meet cluster nodes(集群节点) cluster replicate(集群复制) cluster reset(集群重置) cluster saveconfig cluster set config epoch cluster setslot cluster slaves cluster slots readonly readwrite Connection auth echo ping quit select swapdb Geo geoadd geodist geohash geopos georadius georadiusbymember Hashes hdel hexists hget hgetall hincrby hincrbyfloat hkeys hlen hmget hmset hscan hset hsetnx hstrlen hvals HyperLogLog pfadd pfcount pfmerge Keys del dump exists expire expireat keys migrate move object persist pexpire pexpireat pttl randomkey rename renamenx restore scan sort touch ttl type unlink wait Lists blpop brpop brpoplpush lindex linsert llen lpop lpush lpushx lrange lrem lset ltrim rpop rpoplpush rpush rpushx Pub/Sub psubscribe publish pubsub punsubscribe subscribe unsubscribe Scripting eval evalsha script debug script exists script flush script kill script load Server bgrewriteaof bgsave client getname client kill client list client pause client reply client setname command command count command getkeys command info config get config resetstat config rewrite config set dbsize debug object debug segfault flushall flushdb info lastsave monitor role save shutdown slaveof slowlog time Sets sadd scard sdiff sdiffstore sinter sinterstore sismember smembers smove spop srandmember srem sscan sunion sunionstore Sorted Sets zadd zcard zcount zincrby zinterstore zlexcount zrange zrangebylex zrangebyscore zrank zrem zremrangebylex zremrangebyrank zremrangebyscore zrevrange zrevrangebylex zrevrangebyscore zrevrank zscan zscore zunionstore Strings append bitcount bitfield bitop bitpos decr decrby get getbit getrange getset incr incrby incrbyfloat mget mset msetnx psetex set setbit setex setnx setrange strlen Transactions discard exec multi unwatch watch
watak

KEYS pattern

自1.0.0起可用。

时间复杂度: O(N),其中N是数据库中的键的数量,假设数据库中的键名和给定模式的长度有限。

返回所有匹配的键pattern

虽然此操作的时间复杂度为O(N),但常数时间相当短。例如,运行在入门级笔记本电脑上的 Redis 可以在40毫秒内扫描一百万个密钥数据库。

警告:将 KEYS 视为仅应在生产环境中谨慎使用的命令。在对大型数据库执行它时可能会损坏性能。此命令用于调试和特殊操作,例如更改您的密钥空间布局。请勿在常规应用程序代码中使用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"

Artikel sebelumnya: Artikel seterusnya: