Why Does Redis Have 16 Databases? Uncover the Design Reason
This article explains why a Redis instance creates 16 default databases, how they function as simple namespaces rather than separate applications, how to configure their number, and why Redis clusters support only a single database.
Why Redis Has 16 Databases
In real projects Redis is often used for caching, distributed locks, and message queues. After configuring a Redis server, many developers wonder why Redis creates 16 databases by default.
1. Origin of the 16 Databases
Redis is a dictionary‑structured storage server; a single Redis instance provides multiple dictionaries for storing data. This is similar to having multiple databases in a relational‑database instance, so each dictionary can be regarded as an independent database.
Redis defaults to 16 databases, but the number can be changed by editing the databases setting in redis.conf and restarting the server.
When a client connects, it automatically selects database 0, but the SELECT command can switch to any other database at any time.
2. Proper Understanding of Redis “Database” Concept
Redis does not support custom database names; each database is identified only by a number, so developers must keep their own mapping of what data resides in which database. All databases share the same access password, meaning a client either has access to every database or none.
The FLUSHALL command clears data from all databases at once, which differs from relational databases where each database is cleared independently. Therefore, Redis databases behave more like namespaces and are not intended for storing data of different applications in the same instance. It is recommended to use a separate Redis instance per application, while different databases can be used for different environments (e.g., 0 for production, 1 for testing). An empty Redis instance consumes only about 1 MB of memory.
<img src="https://mmbiz.qpic.cn/mmbiz_png/SJm51egHPPGgWicA5nsBXgRPbj7SHUKNDw4Ypicc0IGM37v644ms66l1RqXx8ibDE03wlUf8EEicmMmC7s37mT68hA/640" />3. Does a Cluster Instance Support Multiple DBs?
In Redis Cluster mode only database 0 exists; the SELECT command is not supported. This limitation distinguishes cluster deployments from single‑node Redis.
Key batch operations are limited: commands like MGET or MSET must operate on keys within the same slot.
Key‑based transactions and Lua scripts are limited: all involved keys must reside on the same node.
Key is the smallest unit of data partitioning; big keys cannot be split across slots.
Multiple databases are not supported: only db0 is available in cluster mode.
Replication is single‑level only; tree‑structured replication is not supported.
4. Summary
Redis instances create 16 default databases named db0 … db15. The number can be changed via the databases configuration. These databases should be viewed as simple namespaces rather than isolated environments for different applications; separate Redis instances are recommended for different apps. In a Redis cluster, only a single database (db0) exists, and the SELECT command cannot be used.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
