using different database at redis command prompt

41,751

Solution 1

Just use the -n argument to choose DB number. It available since Redis 2.4.2.

echo -n "testing" | redis-cli -n 4 -x set my_pass

or

redis-cli -n 4 set my_pass testing

Solution 2

Launch the CLI by issuing command:

redis-cli

Then use the following command:

select <db number>

For example:

select 4
Share:
41,751
shantanuo
Author by

shantanuo

open source contributor

Updated on November 11, 2020

Comments

  • shantanuo
    shantanuo over 3 years

    dThe following works as expected. But how do I insert the data into forth database instead of default "0" from command prompt?

    # echo -n "testing" | /home/shantanu/redis-2.4.2/src/redis-cli -x set my_pass
    OK
    
    # echo -n "testing" | /home/shantanu/redis-2.4.2/src/redis-cli -x select 4; set my_pass
    (error) ERR wrong number of arguments for 'select' command
    
  • d-_-b
    d-_-b about 10 years
    Thanks - I wish they'd add this to the documentation - redis.io/commands/select
  • james-see
    james-see about 7 years
    Thanks for this. In case anyone is using Python in addition to redis-cli, you simply add db=4 to the connection parameters when you initialize a new redis client. Extended example: POOL = redis.ConnectionPool(host='10.0.0.1', port=6379, db=4) which is also referenced at the answer here