4

Trying to organize our Redis keyspaces in a simple and (somewhat) extensible way, we've found an interesting mechanism: databases. The idea would be to a name (say person, for example) to a database number, like 0. Then, all operations on the namespace person would go on the database 0.

What are the drawbacks and advantages of doing this? Is there a better way?

P.S.: We are using Python 2.7.

Thanks very much!

Juan Carlos Coto
  • 11,900
  • 22
  • 62
  • 102

1 Answers1

2

Using multiple Redis databases is strongly discouraged.

Don't use it in production, if it's not a necessity (like when you're dealing with port range restrictions, hosted redis, and the likes).

See this post.

All of our redis instances have the following config parameter:

databases 1

How we deal with this, is the following:

We shard. We connect to a small redis instance first, which only contains connection strings. Given a context/environment, we connect to several redis instances. Most clients have 4 connections: 1 for the connection pool, 1 for read-only config settings, 1 for read of bulk data, 1 for write of bulk data. We put sentinels in between where appropriate.

We use Lua scripting to tie it all conveniently together. See this diagram for a general gist.

Hope this helps, TW

Community
  • 1
  • 1
Tw Bert
  • 3,659
  • 20
  • 28
  • Can you provide some reference as to _why_ it is strongly discouraged? I found references for multiple databases not being supported for Redis *cluster*, but none for single-instance. – Juan Carlos Coto Apr 01 '14 at 15:30
  • I already provided one, where I stated the reason. See above. Here is [another reference](http://stackoverflow.com/questions/16221563/whats-the-point-of-multiple-redis-databases?rq=1). – Tw Bert Apr 01 '14 at 16:43
  • One more: [here](http://stackoverflow.com/questions/16802090/use-multiple-dbs-with-one-redis-lua-script). Please note I said 'strongly discouraged'. It is not, nor are there plans to, deprecate multiple db's. It has been on the agenda for a short time, but decided against. – Tw Bert Apr 01 '14 at 17:09