Redis command to get all available keys?

后端 未结 15 2675
攒了一身酷
攒了一身酷 2020-12-04 04:30

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.

15条回答
  •  长情又很酷
    2020-12-04 05:17

    KEYS pattern

    Available since 1.0.0.

    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.

    Returns all keys matching pattern.

    Warning : This command is not recommended to use because it may ruin performance when it is executed against large databases instead of KEYS you can use SCAN or SETS.

    Example of KEYS command to use :

    redis> MSET firstname Jack lastname Stuntman age 35
    "OK"
    redis> KEYS *name*
    1) "lastname"
    2) "firstname"
    redis> KEYS a??
    1) "age"
    redis> KEYS *
    1) "lastname"
    2) "age"
    3) "firstname"
    

提交回复
热议问题