redis_wrap icon indicating copy to clipboard operation
redis_wrap copied to clipboard

bug with lists

Open jabbalaci opened this issue 10 years ago • 1 comments

Hi,

Iteration over a list contains a bug:

N = 31

nums = get_list(key)

for i in range(N):
    nums.append(i)

back = [e for e in nums]

assert len(nums) == N
print(">> back's length:", len(back))
assert len(back) == N

Output:

>> back's length: 32
Traceback (most recent call last):
  File "./list_fails.py", line 35, in <module>
    fails()
  File "./list_fails.py", line 25, in fails
    assert len(back) == N
AssertionError

The problem is in this function: https://github.com/Doist/redis_wrap/blob/master/redis_wrap/redis_list.py#L41 . Whenever you add 30, you introduce a duplicate.

From the Redis docs (http://redis.io/commands/LRANGE):

"Note that if you have a list of numbers from 0 to 100, LRANGE list 0 10 will return 11 elements, that is, the rightmost item is included. This may or may not be consistent with behavior of range-related functions in your programming language of choice (think Ruby's Range.new, Array#slice or Python's range() function)."

jabbalaci avatar May 30 '15 21:05 jabbalaci

I just sent a pull request. Please review it.

jabbalaci avatar May 30 '15 21:05 jabbalaci