pub struct Connection { /* private fields */ }
Expand description
An open connection to a Redis server.
§Examples
Get a value from the Redis database.
use spin_sdk::redis::Connection;
let conn = Connection::open("redis://127.0.0.1:6379")?;
let payload = conn.get("archimedes-data")?;
if let Some(data) = payload {
println!("{}", String::from_utf8_lossy(&data));
}
Set a value in the Redis database.
use spin_sdk::redis::Connection;
let conn = Connection::open("redis://127.0.0.1:6379")?;
let payload = "Eureka!".to_owned().into_bytes();
conn.set("archimedes-data", &payload)?;
Delete a value from the Redis database.
use spin_sdk::redis::Connection;
let conn = Connection::open("redis://127.0.0.1:6379")?;
conn.del(&["archimedes-data".to_owned()])?;
Publish a message to a Redis channel.
use spin_sdk::redis::Connection;
let conn = Connection::open("redis://127.0.0.1:6379")?;
let payload = request.body().to_vec();
ensure_pet_picture(&payload)?;
conn.publish("pet-pictures", &payload)?;
Implementations§
Source§impl Connection
impl Connection
Source§impl Connection
impl Connection
Source§impl Connection
impl Connection
Source§impl Connection
impl Connection
Source§impl Connection
impl Connection
Sourcepub fn incr(&self, key: &str) -> Result<i64, Error>
pub fn incr(&self, key: &str) -> Result<i64, Error>
Increments the number stored at key by one.
If the key does not exist, it is set to 0 before performing the operation.
An error::type-error
is returned if the key contains a value of the wrong type
or contains a string that can not be represented as integer.
Source§impl Connection
impl Connection
Source§impl Connection
impl Connection
Source§impl Connection
impl Connection
Source§impl Connection
impl Connection
Source§impl Connection
impl Connection
Sourcepub fn execute(
&self,
command: &str,
arguments: &[RedisParameter],
) -> Result<Vec<RedisResult>, Error>
pub fn execute( &self, command: &str, arguments: &[RedisParameter], ) -> Result<Vec<RedisResult>, Error>
Execute an arbitrary Redis command and receive the result.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Connection
impl RefUnwindSafe for Connection
impl Send for Connection
impl Sync for Connection
impl Unpin for Connection
impl UnwindSafe for Connection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more