Redis command to get all available keys?

后端 未结 15 2587
攒了一身酷
攒了一身酷 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:02

    It can happen that using redis-cli, you connect to your remote redis-server, and then the command:

    KEYS *
    

    is not showing anything, or better, it shows:
    (empty list or set)

    If you are absolutely sure that the Redis server you use is the one you have the data, then maybe your redis-cli is not connecting to the Redis correct database instance.

    As it is mentioned in the Redis docs, new connections connect as default to the db 0.

    In my case KEYS command was not retrieving results because my database was 1. In order to select the db you want, use SELECT.
    The db is identified by an integer.

    SELECT 1
    KEYS *
    

    I post this info because none of the previous answers was solving my issue.

    0 讨论(0)
  • 2020-12-04 05:04

    We should be using --scan --pattern with redis 2.8 and later.

    You can try using this wrapper on top of redis-cli. https://github.com/VijayantSoni/redis-helper

    0 讨论(0)
  • 2020-12-04 05:06

    Yes, you can get all keys by using this

    var redis = require('redis');
    redisClient = redis.createClient(redis.port, redis.host);    
      redisClient.keys('*example*', function (err, keys) {
    })
    
    0 讨论(0)
  • 2020-12-04 05:06

    Get All Keys In Redis

    Get all keys using the --scan option:

    $ redis-cli --scan --pattern '*'
    

    List all keys using the KEYS command:

    $ redis-cli KEYS '*'
    
    0 讨论(0)
  • 2020-12-04 05:09

    In order to get all the keys available in redis server, you should open redis-cli and type: KEYS * In order to get more help please visit this page: This Link

    0 讨论(0)
  • 2020-12-04 05:12

    -->Get all keys from redis-cli

    -redis 127.0.0.1:6379> keys *
    

    -->Get list of patterns

    -redis 127.0.0.1:6379> keys d??
    

    This will produce keys which start by 'd' with three characters.

    -redis 127.0.0.1:6379> keys *t*
    

    This wil get keys with matches 't' character in key

    -->Count keys from command line by

    -redis-cli keys * |wc -l
    

    -->Or you can use dbsize

    -redis-cli dbsize
    
    0 讨论(0)
提交回复
热议问题