why the rust consumer could not read redis stream data

76 views Asked by At

I am using rust to consume the redis stream data, this is the minimal reproduce code:

use redis::{
    streams::{StreamId, StreamKey, StreamReadOptions, StreamReadReply},
    Commands, RedisResult,
};
use rust_wheel::{common::util::rd_file_util::join_paths, config::cache::redis_util::get_con};
use serde::Serialize;

fn main() {
    let mut con = get_con();
    let stream_key = "sys:event";
    let stream_id = "0";
    let options = StreamReadOptions::default().count(1).block(1000).noack();
    let result: RedisResult<StreamReadReply> =
        con.xread_options(&[stream_key], &[stream_id], &options);
    if let Err(e) = result.as_ref() {
        return;
    }
    let stream_reply: StreamReadReply = result.unwrap();
    for sk in stream_reply.clone().keys {
        match sk.key.as_str() {
            "sys:event" => {}
            _ => {}
        }
    }
}

now the stream_reply get 0 element, why could not recived the redis stream element? I have read the rust redis source code and told that stream_id=0, read the stream elments from start to end. but the consumer still could not recived any data. this is the redis stream data look like:

{
    "payload": "{\"data\":{\"nickname\":\"jxq\",\"userId\":103},\"id\":706376887005974528,\"msgType\":\"NICKNAME_UPDATE\"}"
}

this is the Cargo.toml:

[package]
name = "rust-learn"
version = "0.1.0"
edition = "2018"

[dependencies]
serde = { version = "1.0.64", features = ["derive"] }
serde_json = "1.0.64"
rust_wheel = { git = "https://github.com/jiangxiaoqiang/rust_wheel.git", branch = "diesel2.0", features = [
    "model",
    "common",
    "rwconfig",
    "texhub"
] }
redis = "0.23.3"

I also tried this command to check the redis stream not null:

> reddwarf-redis-master.reddwarf-cache.svc.cluster.local@6380 (bbw) connected!
> XLEN sys:event
1
0

There are 0 answers