Skip to content
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

$ in xread doesn't work #1145

Closed
isaacleeai opened this issue Mar 8, 2019 · 3 comments
Closed

$ in xread doesn't work #1145

isaacleeai opened this issue Mar 8, 2019 · 3 comments

Comments

@isaacleeai
Copy link

Thanks for wanting to report an issue you've found in redis-py. Please delete this text and fill in the template below.
It is of course not always possible to reduce your code to a small test case, but it's highly appreciated to have as much data as possible. Thank you!

Version:
redis-py vesion: 3.2.0
Redis: 5.0.3

Platform: CentOS7, Python 3.6

Description:
special id $ doesn't work. ( according to Reddis doc , it should fetch the newest unread messages, but it doesn't ).

Code example

if __name__ == '__main__':
    r = redis.Redis(host='localhost', port=6379, db=0)
    encoder = JSONEncoder()
    sample = {"hello": encoder.encode([1234,125, 1235, 1235])} # converts list to string
    stream_name = 'mystream'

    for i in range(10):
        r.xadd(stream_name, sample)

    read_samples = r.xread({stream_name:b"$"}, block = 10000)
    print(read_samples) # prints empty list

But if I replace b"$" with b"0-0", it works fine.

@isaacleeai isaacleeai changed the title $ in xread $ in xread doesn't work Mar 8, 2019
@andymccurdy
Copy link
Contributor

The special $ ID is only for messages that are added to the stream AFTER you start reading with XREAD. In your example above, you add the messages to the stream first, then call XREAD. Doing it in the reverse order will work as expected (though you'll need to add the messages from another process or thread).

@andymccurdy
Copy link
Contributor

I assume this explanation fixed your issue. If you're still having trouble, feel free to reopen this issue.

@wqh17101
Copy link

wqh17101 commented Jul 3, 2023

@andymccurdy Some example code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants