58

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
1
  • 1
    It is important to notice that redis-cli does not allow multiple commands. Commented Nov 24, 2011 at 10:38

2 Answers 2

104

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - I wish they'd add this to the documentation - redis.io/commands/select
47

Launch the CLI by issuing command:

redis-cli

Then use the following command:

select <db number>

For example:

select 4

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.