Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most efficient way to insert an already sorted set into REDIS

I have an already sorted set in memory of size (N) and want to dump it into redis, can it be done in O(N) if inserted head or tail first? or it doesn't matter, and the insertion will be O(log(N!)) ~ O(N log(N))

For further details, redis sorted sets are implemented using a hashmap and a skiplist (for the ordering).

EDIT: this question remains unanswered since quite a bit, or at least the answer is a bit ambiguous for me: Redis: Is ZADD better than O(logN) when the inserted element is at the beginning or end?

like image 313
Daren Avatar asked Sep 29 '22 18:09

Daren


1 Answers

Here are the results from my "empirical" approach which suggest there may be a slight benefit to having order :)

(.venv)foo@bar:~/so_bounty$ python main.py
ascending order
5.57414388657
descending order
5.72963309288
random order
6.75937390327
0 score
5.79048109055
like image 171
Itamar Haber Avatar answered Oct 08 '22 02:10

Itamar Haber