Struct RedisUtil

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

Redis 工具类,封装了一些常用的 Redis 操作。

Implementations§

Source§

impl RedisUtil

Source

pub fn new() -> Result<RedisUtil>

构造函数,初始化 Redis 客户端。

Source

pub fn set<T: ToRedisArgs>(&mut self, key: &str, value: &T) -> RedisResult<bool>

同步设置 Redis 键值对。

Source

pub fn set_with_expiry<T: ToRedisArgs>( &mut self, key: &str, value: &T, expiry_seconds: u64, ) -> RedisResult<()>

同步设置带有过期时间的 Redis 键值对。

Source

pub fn expire(&mut self, key: &str, expiry_seconds: i64) -> RedisResult<bool>

同步为现有键设置过期时间。

Source

pub fn get<T: FromRedisValue>(&mut self, key: &str) -> RedisResult<Option<T>>

同步获取 Redis 键对应的值。

Source

pub fn pipeline_operations<T: ToRedisArgs>( &mut self, keys: Vec<&str>, values: Vec<&T>, ) -> RedisResult<()>

使用 Pipeline 进行批量操作(设置多个键值对)。

Source

pub fn exists(&mut self, key: &str) -> RedisResult<bool>

检查键是否存在。 返回 true 表示键存在,false 表示键不存在。

Source

pub fn del_vec(&mut self, keys: Vec<&str>) -> RedisResult<usize>

删除一个或多个键。 返回删除的键数量。

Source

pub fn del(&mut self, key: &str) -> RedisResult<usize>

删除一个键。 返回删除的键数量。

Source

pub fn ttl(&mut self, key: &str) -> RedisResult<isize>

获取键的剩余生存时间(TTL),单位为秒。

Source

pub fn incr(&mut self, key: &str) -> RedisResult<isize>

对整数类型的键进行原子自增操作。

Source

pub fn decr(&mut self, key: &str) -> RedisResult<isize>

对整数类型的键进行原子自减操作。

Source

pub fn hset(&mut self, key: &str, field: &str, value: &str) -> RedisResult<()>

设置哈希类型的键值对。

Source

pub fn hget(&mut self, key: &str, field: &str) -> RedisResult<Option<String>>

获取哈希类型键的值。

Source

pub fn lpush<T: FromRedisValue>( &mut self, key: &str, value: &str, ) -> RedisResult<T>

向列表左侧推入元素。

Source

pub fn rpop<T: ToString>( &mut self, key: &str, count: Option<usize>, ) -> RedisResult<Option<Vec<String>>>

从列表右侧弹出元素。

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,