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

Optimize _scan() #212

Merged
merged 1 commit into from
Aug 27, 2018
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
13 changes: 7 additions & 6 deletions fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import types
import re
import functools
from itertools import count
from itertools import count, islice

import redis
from redis.exceptions import ResponseError
Expand Down Expand Up @@ -2046,14 +2046,15 @@ def _scan(self, keys, cursor, match, count):
data = sorted(keys)
result_cursor = cursor + count
result_data = []
# subset =

if match is not None:
regex = _compile_pattern(match)
for val in islice(data, cursor, result_cursor):
if regex.match(to_bytes(val)):
result_data.append(val)
else:
regex = None
for val in data[cursor:result_cursor]:
if not regex or regex.match(to_bytes(val)):
result_data.append(val)
result_data = data[cursor:result_cursor]

if result_cursor >= len(data):
result_cursor = 0
return result_cursor, result_data
Expand Down