无涯教程-Redis - KEYS pattern命令函数

166 阅读1分钟

Redis KEYS 命令用于搜索具有匹配模式的键(key)。

KEYS pattern - 返回值

具有匹配模式的键列表(数组)。

KEYS pattern - 语法

以下是Redis KEYS 命令的基本语法。

redis 127.0.0.1:6379> KEYS PATTERN

KEYS pattern - 示例

首先,在Redis中创建一个键(key),并在其中设置一些值。

redis 127.0.0.1:6379> SET tutorial1 redis 
OK 
redis 127.0.0.1:6379> SET tutorial2 mysql 
OK 
redis 127.0.0.1:6379> SET tutorial3 mongodb 
OK 

现在,从关键字教程开始,使用键搜索Redis。

redis 127.0.0.1:6379> KEYS tutorial* 
1) "tutorial3" 
2) "tutorial1" 
3) "tutorial2" 

要获取Redis中所有可用键的列表,请仅使用*

redis 127.0.0.1:6379> KEYS * 
1) "tutorial3" 
2) "tutorial1" 
3) "tutorial2" 

参考链接

www.learnfk.com/redis/keys-…