pub struct RedisAsync;Expand description
同步 Redis 工具类,连接在实例 drop 时释放 异步 Redis 工具类,适用于 Tokio 异步运行时 推荐在 Axum 中间件和异步代码中使用 每个方法独立获取和释放连接,避免连接长时间占用
Implementations§
Source§impl RedisAsync
impl RedisAsync
Sourcepub async fn set<T: ToRedisArgs + Send + Sync>(
key: &str,
value: &T,
) -> RedisResult<()>
pub async fn set<T: ToRedisArgs + Send + Sync>( key: &str, value: &T, ) -> RedisResult<()>
异步设置键值对
Sourcepub async fn set_with_expiry<T: ToRedisArgs + Send + Sync>(
key: &str,
value: &T,
expiry_seconds: u64,
) -> RedisResult<()>
pub async fn set_with_expiry<T: ToRedisArgs + Send + Sync>( key: &str, value: &T, expiry_seconds: u64, ) -> RedisResult<()>
异步设置带过期时间的键值对
Sourcepub async fn set_nx_ex<T: ToRedisArgs + Send + Sync>(
key: &str,
value: &T,
expiry_seconds: u64,
) -> RedisResult<bool>
pub async fn set_nx_ex<T: ToRedisArgs + Send + Sync>( key: &str, value: &T, expiry_seconds: u64, ) -> RedisResult<bool>
异步设置带 NX 和 EX 的键值对(分布式锁)
Sourcepub async fn get<T: FromRedisValue + Send>(key: &str) -> RedisResult<Option<T>>
pub async fn get<T: FromRedisValue + Send>(key: &str) -> RedisResult<Option<T>>
异步获取键对应的值
Sourcepub async fn exists(key: &str) -> RedisResult<bool>
pub async fn exists(key: &str) -> RedisResult<bool>
异步检查键是否存在
Sourcepub async fn del(key: &str) -> RedisResult<i32>
pub async fn del(key: &str) -> RedisResult<i32>
异步删除键
Sourcepub async fn del_vec(keys: &[&str]) -> RedisResult<i32>
pub async fn del_vec(keys: &[&str]) -> RedisResult<i32>
异步删除多个键
Sourcepub async fn ttl(key: &str) -> RedisResult<i64>
pub async fn ttl(key: &str) -> RedisResult<i64>
异步获取 TTL
Sourcepub async fn incr(key: &str) -> RedisResult<i64>
pub async fn incr(key: &str) -> RedisResult<i64>
异步自增
Sourcepub async fn decr(key: &str) -> RedisResult<i64>
pub async fn decr(key: &str) -> RedisResult<i64>
异步自减
Sourcepub async fn hset<K: ToRedisArgs + Send + Sync, V: ToRedisArgs + Send + Sync>(
key: &str,
field: K,
value: V,
) -> RedisResult<()>
pub async fn hset<K: ToRedisArgs + Send + Sync, V: ToRedisArgs + Send + Sync>( key: &str, field: K, value: V, ) -> RedisResult<()>
异步设置哈希字段
Sourcepub async fn hget<T: FromRedisValue + Send>(
key: &str,
field: &str,
) -> RedisResult<Option<T>>
pub async fn hget<T: FromRedisValue + Send>( key: &str, field: &str, ) -> RedisResult<Option<T>>
异步获取哈希字段
Sourcepub async fn lpush<T: ToRedisArgs + Send + Sync>(
key: &str,
value: T,
) -> RedisResult<i32>
pub async fn lpush<T: ToRedisArgs + Send + Sync>( key: &str, value: T, ) -> RedisResult<i32>
异步向列表左侧推入元素
Sourcepub async fn xadd_maxlen<K: ToRedisArgs + Send + Sync, V: ToRedisArgs + Send + Sync>(
key: &str,
maxlen: usize,
field: K,
value: V,
) -> RedisResult<String>
pub async fn xadd_maxlen<K: ToRedisArgs + Send + Sync, V: ToRedisArgs + Send + Sync>( key: &str, maxlen: usize, field: K, value: V, ) -> RedisResult<String>
异步添加 Stream 消息(带自动清理)
Sourcepub async fn xdel<ID: ToRedisArgs + Send + Sync>(
key: &str,
ids: &[&ID],
) -> RedisResult<i32>
pub async fn xdel<ID: ToRedisArgs + Send + Sync>( key: &str, ids: &[&ID], ) -> RedisResult<i32>
异步删除 Stream 消息
Auto Trait Implementations§
impl Freeze for RedisAsync
impl RefUnwindSafe for RedisAsync
impl Send for RedisAsync
impl Sync for RedisAsync
impl Unpin for RedisAsync
impl UnsafeUnpin for RedisAsync
impl UnwindSafe for RedisAsync
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
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more