是否有Redis命令用于获取数据库中的所有密钥?我已经看到一些python-redis库正在获取它们.但是我想知道从redis-client是否有可能.
Is there a Redis command for fetching all keys in the database? I have seen some python-redis libraries fetching them. But was wondering if it is possible from redis-client.
推荐答案尝试查看 KEYS 命令. KEYS *将列出存储在Redis中的所有密钥.
Try to look at KEYS command. KEYS * will list all keys stored in redis.
编辑:请注意KEYS文档页面顶部的警告:
please note the warning at the top of KEYS documentation page:
时间复杂度:,假设数据库中的密钥名称和给定模式的长度有限,则O(N)以N为数据库中密钥的数量.
Time complexity: O(N) with N being the number of keys in the database, under the assumption that the key names in the database and the given pattern have limited length.
更新(V2.8或更高版本): SCAN 是KEYS的更好替代品,因为它既不会阻塞服务器,也不会消耗大量资源.优先使用它.
UPDATE (V2.8 or greater): SCAN is a superior alternative to KEYS, in the sense that it does not block the server nor does it consume significant resources. Prefer using it.
更多推荐
Redis命令获取所有可用密钥?
发布评论