N
N
nepster-web2020-03-24 11:00:22
Redis
nepster-web, 2020-03-24 11:00:22

How to properly partition data in Redis?

So I want to use Redis to pass data between services and for caching.

By default, 16 databases are available in Redis, but I did not quite understand their practical use.

I'll try to explain in detail.
I have some data: (cities, countries, airports, articles, statistics data, etc.).

To store data in Redis, I can use data structures such as hash tables:

Страны HSET id_1 "{объект json}"
Страны HSET id_2 "{объект json}"
Страны HSET id_3 "{объект json}"

HSET airport id_1 "{объект json}"
HSET airport id_2 "{объект json}"
HSET airport id_3 "{объект json}"

HSET record id_1 "{объект json}"
HSET record id_2 "{объект json}"
HSET record id_3 "{объект json}"


or is using databases a better practice? for example:

Database 1: cities
Database 2: countries
Database 3: airports

select 3
SET id_1 "{объект json}"
SET id_2 "{объект json}"
SET id_3 "{объект json}"


How to properly partition data in Redis?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2020-03-24
@nepster-web

In practice, the logical separation is most often used: one database - one "set" of data. For example, sessions can be stored in database 1, background task queues in database 2, and view counters in database 3. This gives certain benefits:

  • related data can be torn off from the rest and transferred to another server
  • in the radish statistics, the memory of individual databases is visible, you can determine what kind of data the server bends
  • related data can be cleaned in bulk through FLUSHDB (I don’t advise doing this on a loaded production, but it’s better than sorting by keys, what to delete and what not)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question