Giter Club home page Giter Club logo

Comments (4)

jettify avatar jettify commented on May 10, 2024

Second variant could be even simpler, with little trick:

cur = b'0'
while cur != 0:
    cur, resp = yield from redis.scan(cur)

from aioredis-py.

jettify avatar jettify commented on May 10, 2024

Little research about scan command in other libraries:

redis-py has really nice api:

def scan_iter(self, match=None, count=None):
    cursor = '0'
    while cursor != 0:
        cursor, data = self.scan(cursor=cursor, match=match, count=count)
        for item in data:
            yield item
# usage
for items in redis.scan_iter():
    print(item)

but I failed to do something similar... since you have to mix yield and yield from

asyncio-redis has cursor abstraction:

cursor = yield from protocol.scan(match='*')
while True:
    item = yield from cursor.fetchone()
    if item is None:
        break
    else:
        print(item)

other python redis libs (tornado-redis, txredisapi, txReids) did nothing about scan api or do not support this command at all.

from aioredis-py.

popravich avatar popravich commented on May 10, 2024

My first variant with with statement doesn't look very good.
I don't want to implement cursor as an explicit object (ie like the one in asyncio-redis).
My intention is to hide cursor but to allow using it if needed.
Here is new sample use cases:
simple usage

cur = '0'
while cur != 0:
    cur, resp = yield from redis.scan(cur)
    for item in resp:
        pass  # handle items

'as cursor' usage

cursor_ctx = yield from redis.scan(0)
# cursor_ctx -- namedtuple with 'cur' and 'resp' fields and __iter__ method
for fut in cursor_ctx:   # or simply: for fut in (yield from redis.scan(0)):
    cur, resp = yield from fut
    for item in resp:
        pass  # handle items

from aioredis-py.

popravich avatar popravich commented on May 10, 2024

For now *scan commands return (cursor, items) tuple.

from aioredis-py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.