48

Why does Redis use integer database numbers instead of strings? It seems like it would be trivial to keep a small internal data structure which maps strings to the “actual” integer.

David Wolever
  • 148,955
  • 89
  • 346
  • 502
  • Better ask on the redis dev list. – bmargulies Jul 07 '11 at 23:44
  • 1
    If I can't get an answer here, that will be my next step… But I try to avoid mailing lists when ever possible :P – David Wolever Jul 08 '11 at 00:22
  • 4
    People who voted to close: could you please leave a comment explaining why? I don't *think* this question “will likely solicit opinion, debate, arguments, polling, or extended discussion” and, I know Redis isn't *that* popular, but I don't think questions about it qualify as “extraordinarily narrow” either. – David Wolever Jul 08 '11 at 00:24
  • The chances of finding someone who *knows* on here are very small. Instead, you get guesses when you ask for motivation. Guesses are 'not constructive'. You may not like mailing lists, but for questions like this, they are the home of the people with the facts. – bmargulies Jul 08 '11 at 01:11
  • I've voted to close because of "not constructive". I don't see how any answer could add to the body of knowledge of this site. Unless antirez himself answers (and the answer would most likely be "no reason, it's just simpler") all answers will be pure speculation. – Theo Jul 08 '11 at 06:54
  • Fair enough — those do seem like good reasons. Thanks for the reply. – David Wolever Jul 08 '11 at 18:50

2 Answers2

49

the reason why Redis does not use strings as DB names but indexes is that the goal and ability of Redis databases is not to provide an outer level of dictionary: Redis dictionaries can't scale to many dictionaries, but just to a small number (it is a tradeoff), nor we want to provide nested data structures per design, so this are just "a few namespaces" and as a result using a numerical small index seemed like the best option.

antirez
  • 18,314
  • 5
  • 50
  • 44
  • 7
    Is there a reason why this is a better approach than treating a DB name as a namespace string prefix? – shazow Jul 18 '11 at 16:32
8

Having named databases doesn't really fit the design goals of redis. For a start, in a system designed for maximum performance, adding a string lookup to every call isn't a great idea when most users put everything in DB 0 anyway.

Another one of the design goals is keeping the core simple - If a requested new command can be implemented by combining existing commands on the client without a huge performance penalty it won't get added to the core system. If you really need named databases, it is trivial to update your client code read a string and send a number to redis.

Tom Clarkson
  • 16,074
  • 2
  • 43
  • 51
  • 2
    “adding a string lookup to every call” — correct me if I'm wrong, but it would only need to do a lookup for each `SELECT` call (ie, to map the symbolic name to the integer), no? – David Wolever Jul 08 '11 at 18:49
  • 1
    True, though that can be close to equivalent depending on how you use databases and connections. – Tom Clarkson Jul 09 '11 at 02:54