Reputation: 653
There are 0 to 15 databases in redis.
I want to create my own database using redis-cli. Is there any command for it?
Upvotes: 60
Views: 111162
Reputation: 381
I found this relevant when I encountered the same question:
Redis different selectable databases are a form of namespacing: all the databases are anyway persisted together in the same RDB / AOF file. However different databases can have keys having the same name, and there are commands available like FLUSHDB, SWAPDB or RANDOMKEY that work on specific databases.
In practical terms, Redis databases should mainly used in order to, if needed, separate different keys belonging to the same application, and not in order to use a single Redis instance for multiple unrelated applications.
The bolding is my addition.
Read more here: https://redis.io/commands/select
For the question of how to select a "database", it is the same answer given here:
$ select 1
And also some useful stuff about persistence, if RDB/AOF were mentioned: https://redis.io/topics/persistence
Upvotes: 7
Reputation: 43235
Redis database is not an equivalent of database names in DBMS like mysql.
It is a way to create isolation and namespacing for the keys, and only provides index based naming, not custom names like my_database
.
By default, redis has 0-15 indexes for databases, you can change that number
databases NUMBER
in redis.conf
.
And then you use SELECT command to select the database you want to work on.
Upvotes: 70
Reputation: 49932
You don't create a database in Redis with a command - the number of databases is defined in the configuration file with the databases
directive (the default value is 16). To switch between the databases, call SELECT
.
Upvotes: 20