processing data in redis

Learn redis

I want to calculate ratio files, as the ratio of traffic that they generated to their size.

There are hashes and htraff nsize, key — the name of the file, the value of, respectively, traffic, and size. To calculate the ratio, now I use such code:

$hsize=$redis->hGetAll("hsize");
$htraff=$redis->hGetAll("hraff");

foreach ($v as $hash=>$size)
 $redis->zAdd("hratio",$htraff[$date][$hash]/$size,$hash);


So you can choose Top50 most popular files. The code works wildly slowly (the last line), which is not surprising.

How can we change this place more efficient? Is processing inside the base (Ala update files set ratio=traff/size), well, or at least a bulk insert of values. Or for this task, the radish is not suitable?
October 8th 19 at 01:15
2 answers
October 8th 19 at 01:17
I'm not special, but in the last Redis has support for LUA stored procedures, maybe that would help?
In stable versions, unfortunately, no. - Rosemary14 commented on October 8th 19 at 01:20
October 8th 19 at 01:19
Looking for something test of radish and other databases. Found one, in which the author claimed that the muscle on the right brake. But in the ensuing discussion, the author presented an indisputable evidence of the incorrectness of the conducted measurements. And the discussion came to the conclusion that neither the muscle nor postgre practically not inferior in performance to the radish.

So the only advantage of radish — ease of use. If the task you want to enable calculations on the server, then I see one solution — the rejection of radish in favor of a muscle or postgre.

read the article here and all the comments — it's worth it.

Find more questions by tags NoSQLRedis