Skip to content

Fix ordered set prepend bug #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/kredis/types/ordered_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ def insert(elements, prepending: false)
return if elements.empty?

elements_with_scores = types_to_strings(elements, typed).map.with_index do |element, index|
score = generate_base_score(negative: prepending) + (index / 100000)
incremental_score = index * 0.000001

score = if prepending
-base_score - incremental_score
else
base_score + incremental_score
end

[ score , element ]
end
Expand All @@ -45,10 +51,8 @@ def insert(elements, prepending: false)
end
end

def generate_base_score(negative:)
current_time = process_start_time + process_uptime

negative ? -current_time : current_time
def base_score
process_start_time + process_uptime
end

def process_start_time
Expand Down