Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using different database at redis command prompt

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 
like image 385
shantanuo Avatar asked Nov 24 '11 07:11

shantanuo


People also ask

How can I change database in Redis?

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.

Can Redis have multiple databases?

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.

Why do we use different databases numbers for Redis?

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.


2 Answers

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 
like image 71
miaout17 Avatar answered Sep 22 '22 09:09

miaout17


Launch the CLI by issuing command:

redis-cli 

Then use the following command:

select <db number> 

For example:

select 4 
like image 27
avichalp Avatar answered Sep 25 '22 09:09

avichalp