skip to Main Content

Possibly related to – Redis command to get all available keys?

I have a Redis server storing SixPack data (https://github.com/sixpack/sixpack – a framework to enable A/B testing). I can monitor the Redis server and see the following sample entries when I run monitor command:

$ redis-cli monitor|grep 'TEST'

I can see that there are several keys being used/set. I am attaching a sample below:

1581720438.878978 [15 127.0.0.1:39722] "GETBIT" "sixpack:e:-28591_:excluded" "2307"
1581720439.623866 [15 127.0.0.1:39722] "LRANGE" "sixpack:e:-28003_:alternatives" "0" "-1"
1581720439.624209 [15 127.0.0.1:39722] "HGET" "sixpack:e:-28003_" "traffic_fraction"
1581720439.624557 [15 127.0.0.1:39722] "GET" "sixpack:e:-28003_:winner"
1581720439.624822 [15 127.0.0.1:39722] "HEXISTS" "sixpack:e:-28003_" "archived"
1581720439.625110 [15 127.0.0.1:39722] "EVALSHA" "bcbf3b3ac336a33c2cd7ad0e1fca28db7b49fdee" "1" "sixpack:e:-28003_Recapture:users" "ac945bf7-285e-4f69-83fd-1336e084a318"

However, when I try to access the keys by running $ redis-cli KEYS '*' command, I only get an empty list (empty list or set).

Updated: I checked that this is not a cluster setup. I also check the DBSIZE command. It returns 0.

How can I derive the keys from the MONITOR output? Is there a way to get all the keys in a Redis CLI?

2

Answers


  1. Chosen as BEST ANSWER

    Based on the hint from @AlisterBulman, I ran the INFO command like this.

     $ redis-cli INFO | grep keys
    

    From the output I can see that the DB number '15' has the keys.

    db15:keys=300869,expires=0,avg_ttl=0
    

    Then I ran this command to get the keys.

    $ redis-cli -n 15 KEYS '*'
    

  2. The appropriate database index should be used when running the KEYS command if more than one Redis database is in use.

    $redis-cli -n <DB number> KEYS '*' # or use --scan
    

    Redis comes with 16 default ‘databases’ which can be used to split the keys up. To use them from the tool, redis-cli -n 2 to start using the 3rd DB (the default is 0). Once inside the tool, or from the API, there is the SELECT 2 command (again, to select the db to use). More can be allowed for – it’s just a number in the redis.conf file.

    The Sixpack A/B testing tool configuration has two methods to be able to choose which Redis database to use – in the configuration is the key (eg) redis_db: 15, or it, and more can be set by environment variable: SIXPACK_CONFIG_REDIS_DB, along with _PORT, _HOST, _PASSWORD & _PREFIX.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search