Struct bitbazaar::redis::RedisTempList
source · pub struct RedisTempList {
pub namespace: Cow<'static, str>,
pub key: String,
pub list_inactive_ttl: Duration,
pub item_inactive_ttl: Duration,
/* private fields */
}Expand description
Connect up to a magic redis list that:
- Has an expiry on the list itself, resetting on each read or write. (each change lives again for
list_inactive_ttltime) - Each item in the list has it’s own expiry, so the list is always clean of old items.
- Each item has a generated unique key, this key can be used to update or delete specific items directly.
- Returned items are returned newest/last-updated to oldest This makes this distributed data structure perfect for stuff like:
- recent/temporary logs/events of any sort.
- pending actions, that can be updated in-place by the creator, but read as part of a list by a viewer etc.
Fields§
§namespace: Cow<'static, str>The namespace of the list in redis (should come in as static, but Cow needed because of deserialization)
key: StringThe key of the list in redis
list_inactive_ttl: DurationIf the list hasn’t been read or written to in this time, it will be expired.
item_inactive_ttl: DurationIf an item hasn’t been read or written to in this time, it will be expired.
Implementations§
source§impl RedisTempList
impl RedisTempList
A managed list entry in redis that will:
- Auto expire on inactivity
- Return items newest to oldest
- Items are set with their own ttl, so the members themselves expire separate from the full list
- Optionally prevents duplicate values. When enabled, if a duplicate is added, the item will be bumped to the front & old discarded.
sourcepub async fn push<'a, T: Serialize + for<'b> Deserialize<'b>>(
self: &'a Arc<Self>,
conn: &mut RedisConn<'_>,
item: T,
) -> RedisTempListItem<T>
pub async fn push<'a, T: Serialize + for<'b> Deserialize<'b>>( self: &'a Arc<Self>, conn: &mut RedisConn<'_>, item: T, ) -> RedisTempListItem<T>
Add a new item to the sorted list.
This will also:
- Autoreset list’s expire time to self.list_inactive_ttl from now
- Clean up expired list items
Returns:
RedisTempListItem
sourcepub async fn extend<'a, T: Serialize + for<'b> Deserialize<'b>>(
self: &'a Arc<Self>,
conn: &mut RedisConn<'_>,
items: impl IntoIterator<Item = T>,
) -> Vec<RedisTempListItem<T>>
pub async fn extend<'a, T: Serialize + for<'b> Deserialize<'b>>( self: &'a Arc<Self>, conn: &mut RedisConn<'_>, items: impl IntoIterator<Item = T>, ) -> Vec<RedisTempListItem<T>>
Add multiple items to the sorted list. Purposely using one ttl for all, should think about why if you’re needing to set different ttls to items you’re adding together!
This will also:
- Autoreset list’s expire time to self.list_inactive_ttl from now
- Clean up expired list items
Returns:
- Some(Vec<RedisTempListItem
>): The resulting item holders for each of the items added, these can be used to further manipulate the items. - None: Something went wrong and the items weren’t added correctly.
sourcepub async fn read_multi_raw<T: Serialize + for<'a> Deserialize<'a>>(
&self,
conn: &mut RedisConn<'_>,
limit: Option<isize>,
) -> Vec<(i64, String, T)>
pub async fn read_multi_raw<T: Serialize + for<'a> Deserialize<'a>>( &self, conn: &mut RedisConn<'_>, limit: Option<isize>, ) -> Vec<(i64, String, T)>
Underlying of RedisTempList::read_multi, but returns the (i64: ttl, String: item key, T: item) rather than RedisTempList
sourcepub async fn read_multi<T: Serialize + for<'a> Deserialize<'a>>(
self: &Arc<Self>,
conn: &mut RedisConn<'_>,
limit: Option<isize>,
) -> Vec<RedisTempListItem<T>>
pub async fn read_multi<T: Serialize + for<'a> Deserialize<'a>>( self: &Arc<Self>, conn: &mut RedisConn<'_>, limit: Option<isize>, ) -> Vec<RedisTempListItem<T>>
Read multiple items from the list, ordered from last updated to least (newest to oldest).
This will also:
- Autoreset list’s expire time to self.list_inactive_ttl from now
- Clean up expired list items
Returns:
- Vec<RedisTempListItem
: The wrapped items in the list from newest to oldest up to the provided limit (if any).
sourcepub async fn read<T: Serialize + for<'a> Deserialize<'a>>(
self: &Arc<Self>,
conn: &mut RedisConn<'_>,
uid: &str,
) -> RedisTempListItem<T>
pub async fn read<T: Serialize + for<'a> Deserialize<'a>>( self: &Arc<Self>, conn: &mut RedisConn<'_>, uid: &str, ) -> RedisTempListItem<T>
Read a specific item given it’s uid.
This will also:
- Autoreset list’s expire time to self.list_inactive_ttl from now
- Clean up expired list items
Returns:
- RedisTempListItem<’a, ’c, T>: The item holder that encapsulates any error logic.
sourcepub async fn delete(&self, conn: &mut RedisConn<'_>, uid: &str)
pub async fn delete(&self, conn: &mut RedisConn<'_>, uid: &str)
Delete a specific item given it’s uid.
This will also:
- Autoreset list’s expire time to self.list_inactive_ttl from now
- Clean up expired list items
sourcepub async fn delete_multi<S: Into<String>>(
&self,
conn: &mut RedisConn<'_>,
uids: impl IntoIterator<Item = S>,
)
pub async fn delete_multi<S: Into<String>>( &self, conn: &mut RedisConn<'_>, uids: impl IntoIterator<Item = S>, )
Delete multiple items via their ids.
This will also:
- Autoreset list’s expire time to self.list_inactive_ttl from now
- Clean up expired list items
Trait Implementations§
source§impl Clone for RedisTempList
impl Clone for RedisTempList
source§fn clone(&self) -> RedisTempList
fn clone(&self) -> RedisTempList
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for RedisTempList
impl Debug for RedisTempList
source§impl<'de> Deserialize<'de> for RedisTempList
impl<'de> Deserialize<'de> for RedisTempList
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for RedisTempList
impl RefUnwindSafe for RedisTempList
impl Send for RedisTempList
impl Sync for RedisTempList
impl Unpin for RedisTempList
impl UnwindSafe for RedisTempList
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
source§impl<T> FromFormData for Twhere
T: DeserializeOwned,
impl<T> FromFormData for Twhere
T: DeserializeOwned,
source§fn from_event(ev: &Event) -> Result<T, FromFormDataError>
fn from_event(ev: &Event) -> Result<T, FromFormDataError>
submit event.source§impl<CustErr, T, Request> FromReq<Cbor, Request, CustErr> for T
impl<CustErr, T, Request> FromReq<Cbor, Request, CustErr> for T
source§async fn from_req(req: Request) -> Result<T, ServerFnError<CustErr>>
async fn from_req(req: Request) -> Result<T, ServerFnError<CustErr>>
source§impl<CustErr, T, Request> FromReq<GetUrl, Request, CustErr> for T
impl<CustErr, T, Request> FromReq<GetUrl, Request, CustErr> for T
source§async fn from_req(req: Request) -> Result<T, ServerFnError<CustErr>>
async fn from_req(req: Request) -> Result<T, ServerFnError<CustErr>>
source§impl<CustErr, T, Request> FromReq<Json, Request, CustErr> for T
impl<CustErr, T, Request> FromReq<Json, Request, CustErr> for T
source§async fn from_req(req: Request) -> Result<T, ServerFnError<CustErr>>
async fn from_req(req: Request) -> Result<T, ServerFnError<CustErr>>
source§impl<CustErr, T, Request> FromReq<PostUrl, Request, CustErr> for T
impl<CustErr, T, Request> FromReq<PostUrl, Request, CustErr> for T
source§async fn from_req(req: Request) -> Result<T, ServerFnError<CustErr>>
async fn from_req(req: Request) -> Result<T, ServerFnError<CustErr>>
source§impl<CustErr, T, Response> FromRes<Cbor, Response, CustErr> for T
impl<CustErr, T, Response> FromRes<Cbor, Response, CustErr> for T
source§async fn from_res(res: Response) -> Result<T, ServerFnError<CustErr>>
async fn from_res(res: Response) -> Result<T, ServerFnError<CustErr>>
source§impl<CustErr, T, Response> FromRes<Json, Response, CustErr> for T
impl<CustErr, T, Response> FromRes<Json, Response, CustErr> for T
source§async fn from_res(res: Response) -> Result<T, ServerFnError<CustErr>>
async fn from_res(res: Response) -> Result<T, ServerFnError<CustErr>>
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
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>
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 moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request