Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 8 additions & 3 deletions aredis/commands/iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ class IterCommandMixin:
"""
RESPONSE_CALLBACKS = {}

async def scan_iter(self, match=None, count=None):
async def scan_iter(self, match=None, count=None, type=None):
"""
Make an iterator using the SCAN command so that the client doesn't
need to remember the cursor position.

``match`` allows for filtering the keys by pattern

``count`` allows for hint the minimum number of returns

``type`` filters results by a redis type
"""
cursor = '0'
while cursor != 0:
cursor, data = await self.scan(cursor=cursor, match=match, count=count)
cursor, data = await self.scan(cursor=cursor, match=match,
count=count, type=type)
for item in data:
yield item

Expand Down Expand Up @@ -80,7 +83,7 @@ async def zscan_iter(self, name, match=None, count=None,

class ClusterIterCommandMixin(IterCommandMixin):

async def scan_iter(self, match=None, count=None):
async def scan_iter(self, match=None, count=None, type=type):
nodes = await self.cluster_nodes()
for node in nodes:
if 'master' in node['flags']:
Expand All @@ -91,6 +94,8 @@ async def scan_iter(self, match=None, count=None):
pieces.extend(['MATCH', match])
if count is not None:
pieces.extend(['COUNT', count])
if type is not None:
pieces.extend(['TYPE', type])
response = await self.execute_command_on_nodes([node], 'SCAN', *pieces)
cursor, data = list(response.values())[0]
for item in data:
Expand Down
6 changes: 5 additions & 1 deletion aredis/commands/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,24 @@ async def wait(self, num_replicas, timeout):
"""
return await self.execute_command('WAIT', num_replicas, timeout)

async def scan(self, cursor=0, match=None, count=None):
async def scan(self, cursor=0, match=None, count=None, type=None):
"""
Incrementally return lists of key names. Also return a cursor
indicating the scan position.

``match`` allows for filtering the keys by pattern

``count`` allows for hint the minimum number of returns

``type`` filters results by a redis type
"""
pieces = [cursor]
if match is not None:
pieces.extend([b('MATCH'), match])
if count is not None:
pieces.extend([b('COUNT'), count])
if type is not None:
pieces.extend([b('TYPE'), type])
return await self.execute_command('SCAN', *pieces)


Expand Down