pub struct StreamBatchIterator { /* private fields */ }Expand description
Iterator for scanning Redis Streams in batches as Arrow RecordBatches.
This iterator fetches stream keys matching a pattern and retrieves their entries, converting them to Arrow RecordBatches for use with Polars. Each entry becomes a row in the output.
Supports two modes:
- Single stream: Provide a specific key and iterate through entries
- Multi-stream: Provide a pattern to SCAN and fetch entries from each
§Example
ⓘ
use polars_redis::{StreamBatchIterator, StreamSchema, BatchConfig};
let schema = StreamSchema::new(vec![
("user_id".to_string(), DataType::Utf8),
("action".to_string(), DataType::Utf8),
]).with_key(true).with_entry_id(true);
let config = BatchConfig::new("events:*").with_batch_size(1000);
let mut iterator = StreamBatchIterator::new(url, schema, config)?;
while let Some(batch) = iterator.next_batch()? {
println!("Got {} entries", batch.num_rows());
}§Output Schema
_key(optional): The Redis stream key_entry_id(optional): The stream entry ID (e.g., “1234567890-0”)_timestamp(optional): Entry timestamp extracted from ID (Int64 ms)- User-defined fields from the stream entries
Implementations§
Source§impl StreamBatchIterator
impl StreamBatchIterator
Sourcepub fn new(url: &str, schema: StreamSchema, config: BatchConfig) -> Result<Self>
pub fn new(url: &str, schema: StreamSchema, config: BatchConfig) -> Result<Self>
Create a new StreamBatchIterator.
§Arguments
url- Redis connection URLschema- Schema configuration for the streamconfig- Batch configuration (pattern, batch_size, etc.)
Sourcepub fn with_start_id(self, id: &str) -> Self
pub fn with_start_id(self, id: &str) -> Self
Set the start ID for XRANGE.
Sourcepub fn with_end_id(self, id: &str) -> Self
pub fn with_end_id(self, id: &str) -> Self
Set the end ID for XRANGE.
Sourcepub fn with_count_per_stream(self, count: usize) -> Self
pub fn with_count_per_stream(self, count: usize) -> Self
Set the maximum entries to fetch per stream.
Sourcepub fn next_batch(&mut self) -> Result<Option<RecordBatch>>
pub fn next_batch(&mut self) -> Result<Option<RecordBatch>>
Get the next batch of data as a RecordBatch.
Sourcepub fn rows_yielded(&self) -> usize
pub fn rows_yielded(&self) -> usize
Get the number of rows (entries) yielded so far.
Auto Trait Implementations§
impl !Freeze for StreamBatchIterator
impl !RefUnwindSafe for StreamBatchIterator
impl Send for StreamBatchIterator
impl Sync for StreamBatchIterator
impl Unpin for StreamBatchIterator
impl !UnwindSafe for StreamBatchIterator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more