Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change between redis database?

Tags:

redis

I am new with redis and I didn't figured out how to create and change to another redis database.

How do I do this?

like image 672
silviomoreto Avatar asked Nov 14 '12 19:11

silviomoreto


People also ask

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.

How do I access my Redis database?

To start Redis client, open the terminal and type the command redis-cli. This will connect to your local server and now you can run any command. In the above example, we connect to Redis server running on the local machine and execute a command PING, that checks whether the server is running or not.

How many Redis databases are there?

Out of the box, every Redis instance supports 16 databases. The database index is the number you see at the end of a Redis URL: redis://localhost:6379/0 . The default database is 0 but you can change that to any number from 0-15 (and you can configure Redis to support more databases, look in redis. conf).


1 Answers

By default there are 16 databases (indexed from 0 to 15) and you can navigate between them using select command. Number of databases can be changed in redis config file with databases setting.

By default, it selects the database 0. To select a specified one, use redis-cli -n 2 (selects db 2)

like image 167
yojimbo87 Avatar answered Sep 24 '22 02:09

yojimbo87