pub struct RedisUtil { /* private fields */ }Expand description
Redis 工具类,封装了一些常用的 Redis 操作。
Implementations§
Source§impl RedisUtil
impl RedisUtil
Sourcepub fn set<T: ToRedisArgs>(&mut self, key: &str, value: &T) -> RedisResult<bool>
pub fn set<T: ToRedisArgs>(&mut self, key: &str, value: &T) -> RedisResult<bool>
同步设置 Redis 键值对。
Sourcepub fn set_with_expiry<T: ToRedisArgs>(
&mut self,
key: &str,
value: &T,
expiry_seconds: u64,
) -> RedisResult<()>
pub fn set_with_expiry<T: ToRedisArgs>( &mut self, key: &str, value: &T, expiry_seconds: u64, ) -> RedisResult<()>
同步设置带有过期时间的 Redis 键值对。
Sourcepub fn set_nx_ex<T: ToRedisArgs>(
&mut self,
key: &str,
value: &T,
expiry_seconds: u64,
) -> RedisResult<bool>
pub fn set_nx_ex<T: ToRedisArgs>( &mut self, key: &str, value: &T, expiry_seconds: u64, ) -> RedisResult<bool>
设置带 NX 和 EX 的键值对,用于分布式锁
Sourcepub fn get<T: FromRedisValue>(&mut self, key: &str) -> RedisResult<Option<T>>
pub fn get<T: FromRedisValue>(&mut self, key: &str) -> RedisResult<Option<T>>
同步获取 Redis 键对应的值。
Sourcepub fn pipeline_operations<T: ToRedisArgs>(
&mut self,
keys: Vec<&str>,
values: Vec<&T>,
) -> RedisResult<()>
pub fn pipeline_operations<T: ToRedisArgs>( &mut self, keys: Vec<&str>, values: Vec<&T>, ) -> RedisResult<()>
使用 Pipeline 进行批量操作(设置多个键值对)。
Sourcepub fn exists(&mut self, key: &str) -> RedisResult<bool>
pub fn exists(&mut self, key: &str) -> RedisResult<bool>
检查键是否存在。 返回 true 表示键存在,false 表示键不存在。
Sourcepub fn del(&mut self, key: &str) -> RedisResult<usize>
pub fn del(&mut self, key: &str) -> RedisResult<usize>
删除一个键。 返回删除的键数量。
Sourcepub fn ttl(&mut self, key: &str) -> RedisResult<isize>
pub fn ttl(&mut self, key: &str) -> RedisResult<isize>
获取键的剩余生存时间(TTL),单位为秒。
Sourcepub fn incr(&mut self, key: &str) -> RedisResult<isize>
pub fn incr(&mut self, key: &str) -> RedisResult<isize>
对整数类型的键进行原子自增操作。
Sourcepub fn decr(&mut self, key: &str) -> RedisResult<isize>
pub fn decr(&mut self, key: &str) -> RedisResult<isize>
对整数类型的键进行原子自减操作。
Sourcepub fn lpush<T: FromRedisValue>(
&mut self,
key: &str,
value: &str,
) -> RedisResult<T>
pub fn lpush<T: FromRedisValue>( &mut self, key: &str, value: &str, ) -> RedisResult<T>
向列表左侧推入元素。
Auto Trait Implementations§
impl Freeze for RedisUtil
impl !RefUnwindSafe for RedisUtil
impl Send for RedisUtil
impl Sync for RedisUtil
impl Unpin for RedisUtil
impl UnsafeUnpin for RedisUtil
impl !UnwindSafe for RedisUtil
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
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