Databases 5 min read

Understanding Redis Default 16 Databases: Concepts, Configuration, and Cluster Limitations

Redis instances provide 16 default logical databases that act as namespaces rather than separate data stores; this article explains their origin, how to configure the number of databases, proper usage of SELECT and FLUSHALL commands, and why multiple databases are unsupported in Redis Cluster mode.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
Understanding Redis Default 16 Databases: Concepts, Configuration, and Cluster Limitations

In many projects Redis is used for caching, distributed locks, and message queues, and a newly installed Redis server creates 16 logical databases by default.

Each database is essentially a separate dictionary within the Redis instance, similar to having multiple databases in a relational DBMS, and they are identified only by numeric indexes.

The number of databases can be changed by editing the databases setting in redis.conf and restarting the server.

Clients connect to database 0 by default, but can switch to another database with the SELECT command, for example:

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

Because Redis does not support custom database names or per‑database passwords, databases should be treated as namespaces; a single Redis instance should serve one application, while different numeric databases can be used to separate environments such as production and testing.

In Redis Cluster mode only database 0 exists, so the SELECT command is unavailable; cluster nodes also impose limits on batch key operations, transactions, and Lua scripts, and the FLUSHALL command clears all databases at once.

Overall, the default 16 databases are configurable namespaces rather than independent stores, and for isolation it is recommended to run separate Redis instances per application, noting that clusters support only a single logical database.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

redisConfigurationClusterdatabasesNamespaces
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

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.