Redis SELECT Effect

I am using redis with several databases (which I switch with the SELECT command).

I store various types of information in redis, and I needed to separate it somehow. I did not like the key prefix to disconnect the type of information, so I created more databases.

I would like to ask if this was the right thing, with a concern about performance?

Also, how much overhead does SELECT cause? If I need to cross some related data from two databases that are better suited (see Pseudocode)?

for data in array { redis_select(0) k = redis_get(...) redis_select(1) k2 = redis_get(k) } 

or

 redis_select(0) k = [] for data in array { k[x] = redis_get(...) } redis_select(1) k2 = [] for data in array { k2[x] = redis_get(k[x]) } 
+4
source share
1 answer

You can use the Redis database concept to separate data. This is fully supported in the current version and will be supported in the future.

Now this is not the recommended solution for data isolation. Better to run multiple instances of Redis. The overhead per instance is very low (less than 1 MB), so you can run several of them on any mailbox. It is more scalable (the workload will be distributed across several processor cores, and not just one). It is more flexible (you can use different configuration parameters for each data set or different dump files). Your client simply needs to open one connection for each instance to access different data sets.

Now, if you still want to use Redis databases and work with performance, you need to estimate the number of additional hits that they represent. With in-memory databases, such as Redis, the cost of all basic operations is almost the same, since it is dominated by communication and protocol management, rather than execution itself. Therefore, when the keys / values โ€‹โ€‹are small, the GET, SET, SELECT commands have the same value. Each time SELECT is executed, it is like executing an extra GET or SET command.

Taking your examples, the first sentence will generate 4 commands per array element. The second sentence will only generate 2 commands for each element, so it is much more efficient. If the number of elements is significant, the SELECT value is negligible in the second sentence, while it is not in the first.

If you plan to iterate arrays to run Redis commands, consider using variable parameter commands (such as MGET / MSET) or pipelining (if your client supports it) to reduce the total number of hits.

+7
source

Source: https://habr.com/ru/post/1390249/


All Articles