pub struct HashBatchIterator { /* private fields */ }Expand description
Iterator for scanning Redis hashes in batches as Arrow RecordBatches.
This iterator fetches hash keys matching a pattern and retrieves their field-value pairs, converting them to Arrow RecordBatches for use with Polars.
The iterator uses Redis SCAN for memory-efficient key iteration and pipelines HGETALL/HMGET commands for efficient data retrieval.
§Example
ⓘ
use polars_redis::{HashBatchIterator, HashSchema, BatchConfig, RedisType};
let schema = HashSchema::new(vec![
("name".to_string(), RedisType::Utf8),
("age".to_string(), RedisType::Int64),
]).with_key(true);
let config = BatchConfig::new("user:*").with_batch_size(1000);
let mut iterator = HashBatchIterator::new(url, schema, config, None)?;
while let Some(batch) = iterator.next_batch()? {
println!("Got {} rows", batch.num_rows());
}§Performance
- Uses
SCANwith configurableCOUNThint for non-blocking iteration - Pipelines multiple
HGETALL/HMGETcommands per batch - Supports projection pushdown (only fetch requested fields)
- Memory-efficient streaming (processes one batch at a time)
Implementations§
Source§impl HashBatchIterator
impl HashBatchIterator
Sourcepub fn new(
url: &str,
schema: HashSchema,
config: BatchConfig,
projection: Option<Vec<String>>,
) -> Result<Self>
pub fn new( url: &str, schema: HashSchema, config: BatchConfig, projection: Option<Vec<String>>, ) -> Result<Self>
Create a new HashBatchIterator.
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.
Returns None when iteration is complete.
Sourcepub fn rows_yielded(&self) -> usize
pub fn rows_yielded(&self) -> usize
Get the number of rows yielded so far.
Auto Trait Implementations§
impl !Freeze for HashBatchIterator
impl !RefUnwindSafe for HashBatchIterator
impl Send for HashBatchIterator
impl Sync for HashBatchIterator
impl Unpin for HashBatchIterator
impl !UnwindSafe for HashBatchIterator
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