Reputation: 3254
I am really confused with redis sorted set.
Lets say I have N number of items in the sorted set. I assumed whenever I add an item, it will be sorted in the set.
If I need the lowest score item, I have to use this.
ZRANGE myitem 0 0
But why is the performance is O(log(N)
). Should it not be O(1)
if it is already sorted & to get the lowest score item?
https://redis.io/commands/zrange
Upvotes: 0
Views: 1859
Reputation: 48932
As noted in the documentation, Redis uses a skip list to implement sorted sets. Skip lists have a lookup time of O(log n).
There are other answers here that go into more detail on the use of this data structure, see here for example.
Upvotes: 1