How to retrieve data from RediSearch with Rust?

537 views Asked by At

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);
}
1

There are 1 answers

0
Yun Jae Jung On BEST ANSWER

This question has been solved - the reason it wasn't working properly is that the function ft_sugget is defined to return Strings when it should in fact be returning a Vector of Strings.