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
impl RedisClient
Sourcepub fn new(connection_string: impl Into<String>) -> Self
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");Sourcepub fn get<T: Extract>(
&self,
key: impl Into<Vec<u8>>,
) -> FunctionResult<Option<T>>
pub fn get<T: Extract>( &self, key: impl Into<Vec<u8>>, ) -> FunctionResult<Option<T>>
Get a value from Redis by key.
Sourcepub fn set<T: Encode>(
&self,
key: impl Into<Vec<u8>>,
value: T,
) -> FunctionResult<()>
pub fn set<T: Encode>( &self, key: impl Into<Vec<u8>>, value: T, ) -> FunctionResult<()>
Set a value in Redis with a key.
Sourcepub fn pipe(&self, commands: Vec<Command>) -> FunctionResult<ResponseStream>
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(),
]);
#}