- Notifications
You must be signed in to change notification settings - Fork 2.6k
Added support for XADD / XREAD / XRANGE / XREVRANGE / XLEN operations #920
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
Conversation
bd46c7b to 7495a20 Compare | The tests have been decorated with an arbitrary redis version as we don't yet know the number @antirez will use for his stable release. Once it is available I can update the decorators. |
| Also, if you are generally happy with this PR, I can look at updating the documentation. I'll hold off in case there are any fundamental problems you see here. |
9c513d8 to 6b3e9ad Compare | I would love to see this PR merged, given that the redis team is working on the consumer groups implementation and the specification is already available |
|
@nicois: The current signature cannot handle "partial streams" if their names are either
Also, quick question (as someone who's fairly new to the redis-py, wanting to understand what is the right way to extend the library): |
| @vtermanis thanks, that's a good point. I can't really comment about the pros and cons of response parser definitions. I was hoping to get some feedback from @andymccurdy . Partly to confirm the signatures were correct, after which the documentation can be updated. Also, I will make a simple modification to support XREVRANGE and XLEN, which I wasn't aware of when I first made this PR. |
196df57 to 6ca2bc2 Compare | @vtermanis I've reverted the count/block to what I originally had. The problem is python2 support. If this were my repository I would ditch python2, but it's not up to me. And python2 requires kwargs with defaults to precede *args. |
27fb05c to 0487886 Compare | Fair enough, makes sense! |
aec486a to 0186808 Compare | Actually, sleeping on it, the *full_streams argument is not very helpful, in practice: the only time you would want to XREAD without providing a message ID is the first iteration around a loop. Every subsequent iteration you'll provide the previous highest message_id. e.g. streams = dict(foo='$', bar='$') while True: stream_activity = redis.xread(block=10000, count=10000, **streams) if stream_activity is None: continue for stream_name, messages in stream_activity.items(): for message_id, payload in messages: do_something(stream_name, message_id, payload) streams[stream_name] = message_id.. so I have removed the *full_streams, allowing me to implement your suggestion. Secondly, in answer to your question around the usage of string_keys_to_dict: it actually makes no appreciable difference. When the class is initialised, the |
This includes: XADD, XREAD, XRANGE, XREVRANGE, XLEN. See http://antirez.com/news/114 for more information. Consumer groups is not yet supported, as its details are still being finalised upstream.
| Hi, I'm already using your patches to redis-py, but came to an unpleasant limitation: My streams are named "log/xxx", "log/yyy", and unfortunately the signature you've chosen for Could you perhaps reconsider the binding? Having keyword arguments for the input parameters put a severe limit on the stream key names, that is, they must be valid Python identifiers. What if you perhaps just transport the desired streams as normal dictionary? xread(self, count=None, block=None, streams) |
| @ArminGruner that's why proposed this approach (earlier in this issue). I agree that having stream names as keyword arguments limiting their names is not great. A workaround with the the pull request the way it currently works it to pass the streams in as a dictionary explicitly, e.g.: redis.xread(**{'log/xxx': '$', 'log/yyy': 'some_id'}) |
| FYI: full documentation on streams was recently added. For example, a general introduction was added on May 18, https://redis.io/topics/streams-intro . |
| Does this commit support |
| Merge please! |
| Hi all, |
| I'd like to know when it will be merged |
| I have given up on this maintainer. I have just switched to using the async python client, which works really well and already has streams support. I've made a really nice websocket cache to sit downstream of redis streams, which would have been a pain with the non-async library anyway. |
| @nicois do you have links to your async python client ? Is it related to aioredis? |
| @bsergean they might have been referring to the |
| I just tried to use this (with python 3.5.2) but it fails if I am not sure if the correct solution is to make a check here, or if the correct design would be to not decode, and letting the user handle it either manually or through decode_responses. |
| As Redis 5 with streams hasn't been stable-released yet, might it make sense to add a Also @nicois for the test decorators, the 'Redis 5' release candidates started numbering from |
| @AngusP 5.0 is on |
| @andymccurdy would you be open to letting others help maintain this library? I'd be happy to help! @alkasm the API does seem final at this stage, the redis.io docs are missing a few commands ( Given this PR is old and in need of some tweaks now as things have changed it seems to me a branch in this report would be the best bet rather than PR'ing downstream?! |
| I've pushed some streams-related changes to my library walrus. The client (which subclasses redis-py's Implementation of low-level APIs: https://github.com/coleifer/walrus/blob/82985ab1ec712cedada9e4b1234178242b1f84f0/walrus/database.py#L126-L431 Higher-level container types: https://github.com/coleifer/walrus/blob/82985ab1ec712cedada9e4b1234178242b1f84f0/walrus/containers.py#L1018-L1397 |
See http://antirez.com/news/114 for more information.