Struct HMGetResult

Source
pub struct HMGetResult<'a, A, B>
where A: Into<Vec<u8>> + Clone, RedisString: Into<B>,
{ /* private fields */ }
Expand description

Opaque type used to hold multi-get results. Use the provided methods to convert the results into the desired type of Rust collection.

Trait Implementations§

Source§

impl<'a, A, B> IntoIterator for HMGetResult<'a, A, B>
where A: Into<Vec<u8>> + Clone, RedisString: Into<B>,

Source§

fn into_iter(self) -> Self::IntoIter

Provides an iterator over the multi-get results in the form of (field-name, field-value) pairs. The type of field-name elements is the same as that passed to the original multi- get call, while the field-value elements may be of any type for which a RedisString Into conversion is implemented.

§Examples

Get a HashMap from the results:

use redis_module::key::HMGetResult;
use redis_module::{Context, RedisError, RedisResult, RedisString, RedisValue};

fn call_hash(ctx: &Context, _: Vec<RedisString>) -> RedisResult {
    let key_name = RedisString::create(None, "config");
    let fields = &["username", "password", "email"];
    let hm: HMGetResult<'_, &str, RedisString> = ctx
        .open_key(&key_name)
        .hash_get_multi(fields)?
        .ok_or(RedisError::Str("ERR key not found"))?;
    let response: Vec<RedisValue> = hm.into_iter().map(|(_, v)| v.into()).collect();
    Ok(RedisValue::Array(response))
}

Get a Vec of only the field values from the results:

use redis_module::{Context, RedisError, RedisResult, RedisString, RedisValue};
use redis_module::key::HMGetResult;

fn call_hash(ctx: &Context, _: Vec<RedisString>) -> RedisResult {
    let key_name = RedisString::create(None, "config");
    let fields = &["username", "password", "email"];
    let hm: HMGetResult<'_, &str, RedisString> = ctx
         .open_key(&key_name)
         .hash_get_multi(fields)?
         .ok_or(RedisError::Str("ERR key not found"))?;
    let response: Vec<RedisValue> = hm.into_iter().map(|(_, v)| RedisValue::BulkRedisString(v)).collect();
    Ok(RedisValue::Array(response))
}
Source§

type Item = (A, B)

The type of the elements being iterated over.
Source§

type IntoIter = HMGetIter<'a, A, B>

Which kind of iterator are we turning this into?

Auto Trait Implementations§

§

impl<'a, A, B> Freeze for HMGetResult<'a, A, B>

§

impl<'a, A, B> RefUnwindSafe for HMGetResult<'a, A, B>

§

impl<'a, A, B> !Send for HMGetResult<'a, A, B>

§

impl<'a, A, B> !Sync for HMGetResult<'a, A, B>

§

impl<'a, A, B> Unpin for HMGetResult<'a, A, B>
where RedisString: Sized, B: Unpin,

§

impl<'a, A, B> UnwindSafe for HMGetResult<'a, A, B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.