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

Already on GitHub? Sign in to your account

Adds robustness to the zremrangebyrank method #95

Merged
merged 1 commit into from May 20, 2014

Conversation

Projects
None yet
2 participants
Contributor

timherby commented Feb 11, 2014

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

Adds robustness to the zremrangebyrank method to not error when the s…
…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

Contributor

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

Merge pull request #95 from timherby/add-missing-type-and-empty-checks
Adds robustness to the zremrangebyrank method

@caius caius merged commit bf1b846 into guilleiguaran:master May 20, 2014

1 check passed

default The Travis CI build passed
Details
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