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
Redis databases are numbered from 0 to 15 and, by default, you connect to database 0 when you connect to your Redis instance. However, you can change the database you're using with the select command after you connect: select 15.
Redis comes with support for multiple databases, which is very similar to the concept in SQL databases. In SQL databases, such as MySQL, PostgreSQL, and Oracle, you can define a name for your databases. However, Redis databases are represented by numbers.
Using multiple databases in a single instance may be useful in the following scenario: Different copies of the same database could be used for production, development or testing using real-time data. People may use replica to clone a redis instance to achieve the same purpose.
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
Launch the CLI by issuing command:
redis-cli
Then use the following command:
select <db number>
For example:
select 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With