Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Redis use integer database numbers?

Tags:

redis

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.

like image 719
David Wolever Avatar asked Jul 07 '11 23:07

David Wolever


People also ask

Why do we use different databases numbers for Redis?

Using multiple databases in a single instance may be useful in the following scenario: Different copies of the same database could be used for production, development or testing using real-time data. People may use replica to clone a redis instance to achieve the same purpose.

Can Redis store numbers?

Redis stores integers in their integer representation, so for string values that actually hold an integer, there is no overhead for storing the string representation of the integer.

How data is stored in Redis database?

All Redis data resides in memory, which enables low latency and high throughput data access. Unlike traditional databases, In-memory data stores don't require a trip to disk, reducing engine latency to microseconds.

What is default database in Redis?

Redis databases are numbered from 0 to 15 and, by default, you connect to database 0 when you connect to your Redis instance. However, you can change the database you're using with the select command after you connect: select 15.


1 Answers

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.

like image 196
antirez Avatar answered Sep 20 '22 05:09

antirez