I have read the redis-python document and searched online, I can not find anything about the db
parameter for Redis()
. What is it use for?
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.
That's why db parameter is used. When we start redis-cli it's show or used 0 index logical database. If you want to change the default 0 index database run this command select 1 #index 1 logical database selected. After this we can run different commands specific to selected database.
Redis is an in-memory key-value pair database typically classified as a NoSQL database. Redis is commonly used for caching, transient data storage and as a holding area for data during analysis in Python applications. Redis is an implementation of the NoSQL database concept.
By default, redis has 16 databases, which can be addressed by their indexes. This is what it's for.
See SELECT command.
Redis by default consists of 16 logical databases. Starting from 0 index and ending with 15.
That's why db parameter is used.
When we start redis-cli it's show or used 0 index logical database.
If you want to change the default 0 index database run this command select 1 #index 1 logical database selected
After this we can run different commands specific to selected database. In our case we are using 1 index logical database.
flushdb swapdb
Note In redis cluster we can't used select command and only support 0 database.
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