Dragonfly Cloud announces new enterprise security features - learn more

Error: redis cluster does not support multiple databases

What's Causing This Error

The error "redis cluster does not support multiple databases" typically arises due to a fundamental limitation of Redis Cluster. Redis Cluster, the official high-availability solution provided by Redis, doesn't support multiple databases.

In the standalone version of Redis, we can have separate logical databases (the select command), numbered from 0 to an upper limit set in the configuration file (default is 16). However, this feature is not available in the Redis Cluster specification. The reason for this design choice is that maintaining consistency among keyspace events across multiple databases makes it significantly more complex when dealing with a distributed database system like Redis Cluster.

Solution - Here's How To Resolve It

There are essentially two main approaches to address this issue:

  1. Use Keyspaces instead of Databases: In Redis, you might use multiple databases to avoid key name collisions. Instead, consider using namespaced keys in Redis Cluster. A namespace is simply a prefix on your keys, so instead of key, you would use namespace:key. By replacing different databases with different namespaces, you can avoid key collision and simulate the same functionality as multiple databases.

  2. Separate Redis Clusters: If different databases are independent of each other, you could also setup separate Redis Clusters for each of them. This way, each database could run its own Redis Cluster without impacting others. But be aware: managing multiple clusters may increase the complexity of your environment.

It's important to carefully plan your data model and choose the right approach based on your applications' specific needs and constraints.

Was this content helpful?

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost