简体   繁体   中英

How to retrieve data from RediSearch with Rust?

I'm trying to use Rust and get autocomplete data from RediSearch with the FT.SUGGET command but it ends up retrieving a None value even though when I run FT.SUGGET directly with the command prompt it properly gives responses. This is my code which format works perfectly well with sets and gets in Redis. FT.SUGADD works properly in this as well. Thanks for the future help!

pub fn ft_sugadd(index: String, field: String) -> redis::RedisResult<()>
{
    let client = redis::Client::open("redis://127.0.0.1/")?;
    let mut con = client.get_connection()?;
    redis::cmd("FT.SUGADD").arg(index).arg(field).arg("1".to_string()).query(&mut con)?;
    Ok(())
}

pub fn ft_sugget(index: String, field: String) -> redis::RedisResult<String>
{
    let client = redis::Client::open("redis://127.0.0.1/")?;
    let mut con = client.get_connection()?;
    let data_value = redis::cmd("FT.SUGGET").arg(index).arg(field).arg("fuzzy".to_string()).query(&mut con)?;
    Ok(data_value)
}

fn main()
{
    ft_sugadd("dictionary".to_string(), "Bob".to_string()).ok();
    let remember = ft_sugget("dictionary".to_string(), "Bo".to_string()).ok();
    println!("Hello {:?}", remember);
}

这个问题已经解决了——它不能正常工作的原因是函数 ft_sugget 被定义为返回字符串,而实际上它应该返回一个字符串向量。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM