Databases 6 min read

Why Does Redis Have 16 Databases by Default? Origins and Best Practices

Redis creates 16 logical databases by default, a design inherited from its early architecture; this article explains the origin of that number, how to modify it via configuration, the proper way to view these databases as namespaces, and the limitations when using Redis in cluster mode.

ITPUB
ITPUB
ITPUB
Why Does Redis Have 16 Databases by Default? Origins and Best Practices

1. Origin of the 16 Databases

Redis stores data in a dictionary; a single Redis instance provides multiple dictionaries that can be selected by number, similar to multiple databases in a relational DB. By default Redis creates 16 such logical databases, numbered 0‑15.

2. How to Change the Number of Databases

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

Clients connect to database 0 by default, but can switch with the SELECT command.

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

3. Correct Understanding of Redis “Databases”

Redis does not allow naming databases; they are identified only by number, so developers must track which data resides in which DB. All databases share the same access password; a client can either access all or none. The FLUSHALL command clears data from every logical database, unlike relational DBs where each database is cleared separately.

# Remove all keys from all databases
redis 127.0.0.1:6379> FLUSHALL

Because each DB acts more like a namespace, it is not recommended to store data for different applications in separate logical DBs of the same instance. Instead, use separate Redis instances per application, using different DB numbers only for different environments (e.g., 0 for production, 1 for testing).

4. Databases in Redis Cluster

In cluster mode Redis provides only a single logical database (db0); the SELECT command is not supported. Other cluster limitations include limited batch key operations, key‑based transaction and Lua script restrictions, and a single‑level replication model.

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

Key‑based transaction and Lua script limited to one node

Key is the smallest partition unit; big keys cannot be partitioned

No multiple databases: only db0 in cluster mode

Replication supports only one level, no tree‑like replication

5. Summary

Redis instances create 16 logical databases by default, identified only by number. The count can be altered via the databases setting in the configuration file. These databases function as namespaces rather than isolated stores; different applications should use separate Redis instances. In cluster mode only db0 exists, and multiple logical databases are not supported.

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.

CacheredisClusterdatabases
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

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.