Skip to content

Commit 90129a6

Browse files
authored
Fixed call to ZADD in Lua script (#209)
Calling ZRANGE with WITHSCORES will return list with [member, score, member, score, ...] Iterate over with step -2 will iterate in reverse and skip every second index. [i] is the score, [i - 1] is the member. ZADD syntax: ZADD key [NX|XX] [CH] [INCR] score member Reduced delay in tests to trigger cancel with full backup q demonstrating issue.
1 parent 8e1476e commit 90129a6

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

CHANGELOG.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
UNRELEASED
2+
----------
3+
4+
* Fixed error in Lua script introduced in 3.0.0.
5+
16
3.0.0 (2020-07-03)
27
------------------
38

channels_redis/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ async def _brpop_with_clean(self, index, channel, timeout):
330330
# of the main message queue in the proper order; BRPOP must *not* be called
331331
# because that would deadlock the server
332332
cleanup_script = """
333-
local backed_up = redis.call('ZRANGE', ARGV[2], 0, -1)
334-
for i = #backed_up, 1, -1 do
335-
redis.call('ZADD', ARGV[1], backed_up[i])
333+
local backed_up = redis.call('ZRANGE', ARGV[2], 0, -1, 'WITHSCORES')
334+
for i = #backed_up, 1, -2 do
335+
redis.call('ZADD', ARGV[1], backed_up[i], backed_up[i - 1])
336336
end
337337
redis.call('DEL', ARGV[2])
338338
"""

tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ async def test_receive_cancel(channel_layer):
445445
task = asyncio.ensure_future(channel_layer.receive(channel))
446446
await asyncio.sleep(delay)
447447
task.cancel()
448-
delay += 0.001
448+
delay += 0.0001
449449

450450
try:
451451
await asyncio.wait_for(task, None)

0 commit comments

Comments
 (0)