Databases 5 min read

Understanding Redis’s Default 16 Databases: Origin, Configuration, and Best Practices

This article explains why Redis creates 16 default databases, how to configure their number, the proper way to view these databases as namespaces, and why multiple applications should use separate Redis instances, especially noting that Redis clusters support only a single db0.

Architecture Digest
Architecture Digest
Architecture Digest
Understanding Redis’s Default 16 Databases: Origin, Configuration, and Best Practices

1. Origin of the 16 Databases

Redis is a dictionary‑structured storage server; a single Redis instance provides multiple dictionaries that can be addressed independently, similar to having several databases in a relational DBMS. By default Redis creates 16 such logical databases.

The number can be changed by editing the redis/redis.conf file’s databases setting and restarting the server.

2. Correct Understanding of Redis “Database” Concept

Redis does not allow custom names for databases; they are identified only by numeric indices, so developers must keep their own mapping of which data resides in which DB. All databases share the same access password, meaning a client can either access all databases or none.

To switch databases, the client uses the SELECT command, e.g.:

# 切库
redis> SELECT 1 # 默认0号db,切换为1号db
OK
redis [1] > GET username # 从1号库中获取 username
(nil)

The FLUSHALL command clears data from every logical database in the instance, which differs from relational databases where each database is cleared independently.

3. Multiple Databases in Cluster Mode

In Redis Cluster mode only a single logical database (db0) exists; the SELECT command is not supported. Other limitations include restricted key‑batch operations, limited Lua scripting, and a single‑level replication topology.

4. Summary

Redis defaults to 16 logical databases, configurable via the databases parameter in the configuration file. These databases act as namespaces rather than isolated stores, so different applications should use separate Redis instances. In cluster deployments only db0 is available, and multiple logical databases are not supported.

cacheClusteringRedisconfigurationdatabasesKey-Value Store
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.