Maximum number of databases in redis
Asked Answered
C

5

27

In redis, select "number" gives access to specific database at that index. I my redis config it is set 16(why ?). We require high scaling of our application so what is the max limit for that?

Copyhold answered 20/4, 2016 at 6:13 Comment(3)
So, your plan for "scaling" is to use separate databases in the same redis process? What kind of scaling is this?Preventive
We have situations like this Situation1: tenant1 -> nginx+lua+redis tenant2 -> nginx+lua+redis,....... If a particular tenant at max request processing the we want separate databases in the same redis process. Situation2: Every request to each tenant will pass through proxy_server with redis, to load balance this we also need scaling here.Copyhold
You need separate redis processes (or redis cluster), not separate databases.Preventive
Y
29

The default number of Redis databases is 16, but can be configured to more. You probably have 16 in your config because of that default (see Storing Data with Redis).

Databases (in Redis) are a way to partition data logically (think "namespace", "key-space" or, in RDBMS terms, a schema). Redis databases have nothing to do with scalability, so your "max limit" question is out of context.

To scale you would want to do as Sergio suggests in his comment: create separate Redis instances/clusters for separate applications.

Younglove answered 27/12, 2018 at 21:11 Comment(0)
M
14

Answer: 1 Million (Maybe) or 100K on Linux (Maybe)

Official Info

So the official documentation indicates that the default setting is 16. This may be changed in redis.conf. The official documentation does not indicate the range that is allowed here.

Original Research

Through experimentation on my local Windows 10 WSL Debian install I found that I could set the conf value to anything and the server would start up fine.

However when I then attempted to select a database via command line my computer would freeze. I tried several values and the system worked perfectly and quickly at 1,000,000 (one million) and froze out at 10,000,000 (ten million). This number seems rather arbitrary in the computer world so either it is a memory limitation (seems unlikely but I don't know WSL's memory handling) or an arbitrary limitation set by the developers.

I ran some similar tests on my CentOS 7 Box and redis refused to start at 1 Million. But started fine at 100 thousand. No idea why it's different from my windows system or why it just refused to start instead of starting and then failing when a database was selected like my WSL version.

Disclaimer

As already stated by @kit in his previous answer databases are not designed for "scaling" but rather for "namespaces". For example a SAAS may run one code base but hundreds of clients each client with their own "namespace" or redis database. This allows you to flush a client without affecting others and minimize the administrative overhead. But running dozens of unique wordpress instances would be better suited for a unique install of redis each.

Meara answered 23/10, 2020 at 18:9 Comment(3)
please, just asking, does this issue relate to maxmemory-policyBenedikt
also, any idea of how this can be fixed if encountered on aws elasticaheBenedikt
@IsraelObanijesu I do not know if maxmemory-policy or aws elasticache is in any way related to this Redis server answer. I suggest you ask a new question (probably a separate question for each of these comments) to find out.Meara
G
9

The default number of databases in Redis is 16,index:0~15。You can edit your redis.conf file to adjust this number:

Steps:

1)edit config file

vi /etc/redis.conf

Default config path is /etc/redis.conf on Centos when installed with Yum.

2)find keyword:"databases"

# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
databases 16

databases 16:16 is the default on new installations

3)Update the number of databases:

databases 30

4)end,save and quit

Garden answered 23/7, 2021 at 8:43 Comment(0)
B
2

The default number of databases is limited to 16. You can change it by making the changes in etc/redis/redis.conf file. sudo vim etc/redis/redis.conf

change databases 16 to databases 150 ,you can type any number instead of 150.

Also, change supervised no to supervised systemd in redis.conf file.

Restart redis: sudo systemctl restart redis.service

Now try selecting any databases higher that 16.

redis-cli select 34

Borax answered 24/1, 2023 at 6:3 Comment(0)
O
2

Answer is "unlimited"... Here is the question and its answer from redis faqs page:

How many Redis databases can I create and manage?

The number of Redis databases is unlimited. The limiting factor is the available memory in the cluster, and the number of shards in the subscription.

Note the impact of the specific database configuration on the number of shards it consumes. For example: -Enabling database replication, without enabling database clustering, creates two shards: a master shard and a replica shard. -Enabling database clustering creates as many database shards as you configure. -Enabling both database replication and database clustering creates double the number of database shards you configure.

for mor details: https://redis.com/faqs/#:~:text=The%20number%20of%20Redis%20databases,of%20shards%20in%20the%20subscription.

Oligoclase answered 20/2, 2023 at 14:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.