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?
Asked
Active
Viewed 1.3k times
2 Answers
33
By default, redis has 16 databases, which can be addressed by their indexes. This is what it's for.
See SELECT command.

Sergio Tulentsev
- 226,338
- 43
- 373
- 367
-
1+1 - See also [redis.conf](https://github.com/antirez/redis/blob/46319094dba97e1e5627ad52687d8d9dab26c070/redis.conf#L115-118) – Sean Vieira Jun 24 '14 at 16:55
-
Note that these "databases" are actually different namespaces in the same database. Besides the fact that this feature is not supported in the upcoming v3 (cluster version), using it may lead to unexpected results in terms of performance. You can read more about this in this blog post: http://redislabs.com/blog/benchmark-shared-vs-dedicated-redis-instances – Itamar Haber Jun 24 '14 at 18:27
3
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.

Muhammad Faizan Fareed
- 3,298
- 34
- 30