Skip to content
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

Adds robustness to the zremrangebyrank method #95

Merged

Conversation

timherby
Copy link
Contributor

I'm running into an error when removing the last item of a set, and then trying to trim a set down to a specific cap. With Redis, I don't need to check the length of a set before calling zremrangebyrank so I don't want to put that check in my production code. The set is missing because it gets removed by remove_key_for_empty_collection.

Here is the pseudocode for repro. This block will apply a diff update to an existing list, but fails in FakeRedis if the last item gets removed:

    if items_to_remove.any?
      list.redis.zrem list.key, items_to_remove.map { |i| list.to_redis(i) }
    end

    if items_to_add.any?
      list.merge items_to_add
    end

    # prune the list to fit within the cap
    list.remrangebyrank(0, -1 - Settings.buffer_size)

This pull request adds the same validation all the other methods use (see zrevrangebyscore), and also moves the method above next to its cousin zremrangebyscore rather than being next to the disssimilar zinterstore and zunionstore

…et is missing (since the set may have been removed by remove_key_for_empty_collection because it was empty)
mkdynamic added a commit to delighted/fakeredis that referenced this pull request Mar 6, 2014
@timherby
Copy link
Contributor Author

timherby commented May 5, 2014

Bump. Any chance we can get this pulled into master? Looks like it's useful to others as it was used by @mkdynamic.

caius added a commit that referenced this pull request May 20, 2014
Adds robustness to the zremrangebyrank method
@caius caius merged commit bf1b846 into guilleiguaran:master May 20, 2014
@caius
Copy link
Collaborator

caius commented May 20, 2014

Many thanks for your contribution! 😀🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants