https://github.com/alkasm/streamtools
Tools for working with Redis Streams
https://github.com/alkasm/streamtools
Last synced: 28 days ago
JSON representation
Tools for working with Redis Streams
- Host: GitHub
- URL: https://github.com/alkasm/streamtools
- Owner: alkasm
- Created: 2018-08-20T21:18:55.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-20T21:22:41.000Z (almost 8 years ago)
- Last Synced: 2025-01-13T05:29:06.193Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Example Usage
```python
from streamtools import StreamsClient, StreamsInteractor, StreamsReader
import random
# start the Redis Streams client
client = StreamsClient('localhost')
# write some random stuff to two streams
writer = StreamsInteractor(client)
for i in range(100):
x = random.randint(0, 100)
writer.xadd('ex-stream-1', **{'x': x, 'x+5': x + 5})
writer.xadd('ex-stream-2', **{'x': x, 'x+7': x + 7})
# iterate through all values written, starting with the earliest values
streams = {'ex-stream-1': 0, 'ex-stream-2': 0}
reader = StreamsReader(client, streams, continuous=False)
for data in reader:
print(data)
```
> StreamData(id='1534799601773-0', key='ex-stream-1', data={'x+5': '26', 'x': '21'})
> StreamData(id='1534799601773-0', key='ex-stream-2', data={'x+7': '28', 'x': '21'})
> StreamData(id='1534799601773-1', key='ex-stream-1', data={'x+5': '34', 'x': '29'})
> StreamData(id='1534799601773-1', key='ex-stream-2', data={'x+7': '36', 'x': '29'})
> StreamData(id='1534799601774-0', key='ex-stream-1', data={'x+5': '41', 'x': '36'})
> StreamData(id='1534799601774-0', key='ex-stream-2', data={'x+7': '43', 'x': '36'})
> ...