Struct RedisClient

Source
pub struct RedisClient { /* private fields */ }
Expand description

Redis client for Function host interfaces.

This client is used to connect to a Redis or Valkey instance that you own.

This client uses Momento’s host-provided connection cache, which keeps connections alive across invocations of your Function for reuse.

Implementations§

Source§

impl RedisClient

Source

pub fn new(connection_string: impl Into<String>) -> Self

Create a new Redis client from a connection string.

Note that the redis/valkey you are connecting to must be accessible to the Functions host environment. If you are using public Momento endpoints, you will only be able to connect to public caches - that is not a reasonable way to set up a production environment. If you want to use a private cache for a real application, please get in touch with support@momentohq.com

let client = RedisClient::new("valkey://my.valkey.instance:6379");
Source

pub fn get<T: Extract>( &self, key: impl Into<Vec<u8>>, ) -> FunctionResult<Option<T>>

Get a value from Redis by key.

Source

pub fn set<T: Encode>( &self, key: impl Into<Vec<u8>>, value: T, ) -> FunctionResult<()>

Set a value in Redis with a key.

Source

pub fn delete(&self, key: impl Into<Vec<u8>>) -> FunctionResult<()>

Delete a key from Redis.

Source

pub fn pipe(&self, commands: Vec<Command>) -> FunctionResult<ResponseStream>

Execute redis commands

let response_stream = client.pipe(vec![
    Command::builder().set("my_key", "my_value")?.build(),
    Command::builder().get("my_key").build(),
    Command::builder()
        .any("FT.SEARCH")
        .arg(r#"test_index "*=>[KNN 5 @vector_a $query_vector]" PARAMS 2 query_vector "\xcd\xccL?\x00\x00\x00\x00\x00\x00\x00\x00""#)
        .build(),
]);

#}

Auto Trait Implementations§

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.