Skip to content

Commit

Permalink
Merge pull request #212 from thedrow/patch-1
Browse files Browse the repository at this point in the history
Optimize _scan()
  • Loading branch information
bmerry authored Aug 27, 2018
2 parents 8098106 + 72ff3c2 commit c729b18
Showing 1 changed file with 7 additions and 6 deletions.
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

0 comments on commit c729b18

Please sign in to comment.