Comments (4)
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.
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.
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.
For now *scan
commands return (cursor, items) tuple.
from aioredis-py.
Related Issues (20)
- docs:: Add stream snippet in the docs
- Aws redis 'Connection closed by server' exception occurs in my program running in aws ecs fargate
- Redis.zrevrangebyscore was wrong
- aioredis.exceptions.ResponseError: wrong number of arguments for 'hset' command HOT 1
- Sentinel cannot select db! HOT 1
- Add `nx`, `xx`, `gt` and `lt` to `.expire` HOT 1
- ConnectionError: OSError: File name too long when specifying ssl_ca_certs HOT 1
- RuntimeError: There is no current event loop in thread 'MainThread'. HOT 2
- zrevrangebyscore in aioredis in different than in redis HOT 2
- aioredis: await wasn't used with future
- Timeout Error 110, Can reconnections be handled gracefully?
- 2.0.1: pytest is failing HOT 2
- Library not works with Python 3.11 HOT 3
- Archive project? HOT 10
- pubsub.get_message(blocking_timeout) don't work with async_timeout.timeout HOT 2
- TypeError: duplicate base class TimeoutError HOT 2
- coroutine 'Connection.disconnect' was never awaited
- python3.7 import aioredis faild
- Too many simultaneous connections
- Add support for Python 3.11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aioredis-py.