Databases 6 min read

Understanding Redis’s Default 16 Databases and Their Proper Use

This article explains why Redis creates 16 logical databases by default, how to configure their number, the correct way to treat these databases as namespaces rather than separate stores, and why multiple databases are not supported in Redis Cluster mode.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Understanding Redis’s Default 16 Databases and Their Proper Use

1. Origin of the 16 Databases

Redis is a dictionary‑based 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 logical databases, a value that can be changed by editing the databases directive in redis/redis.conf and restarting the server.

# Switch database
redis> SELECT 1   # default is DB 0, switch to DB 1
OK
redis[1]> GET username   # query key from DB 1
(nil)

In practice you can also specify the desired database number in the Redis configuration file for each application.

2. Correct Understanding of Redis “Database” Concept

Redis does not allow custom names for databases; they are identified only by numeric indexes, so developers must keep their own mapping of which data belongs to which DB. All databases share the same access password, meaning a client can either access every DB or none. The FLUSHALL command clears data from all databases in the instance, which differs from relational DBMS where each database can be cleared independently. Therefore, Redis databases behave more like logical namespaces and are not intended for storing data of unrelated applications. A common pattern is to use separate Redis instances for different applications, while using different DB numbers within the same instance for different environments (e.g., DB 0 for production, DB 1 for testing).

# Clear all data from every database in the instance
redis 127.0.0.1:6379> FLUSHALL

3. Multi‑Database Support in Cluster Mode

In a Redis Cluster, the SELECT command cannot be used because the cluster operates with a single logical database (db0). The cluster mode also imposes other limitations such as restricted batch key operations, limited Lua scripting, and a single‑level replication topology.

Key batch operations are limited (e.g., MGET/MSET must target keys in the same slot).

Lua scripts and transactions must operate on keys that reside in the same node.

Only one logical database (db0) is available; multiple databases are not supported.

Replication is single‑level only; tree‑shaped replication is not allowed.

4. Summary

Redis creates 16 logical databases by default, identified only by numeric indexes. The number can be changed via the databases setting in the configuration file. These databases should be viewed as lightweight namespaces; different applications should use separate Redis instances rather than sharing databases. In cluster mode, only a single database (db0) exists, so the multi‑database feature is unavailable.

RedisconfigurationClusterdatabasesnamespace
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

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.