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_ttl time)
  • 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: String

The key of the list in redis

§list_inactive_ttl: Duration

If the list hasn’t been read or written to in this time, it will be expired.

§item_inactive_ttl: Duration

If an item hasn’t been read or written to in this time, it will be expired.

Implementations§

source§

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.
source

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: The resulting item holder which can be used to further manipulate the items.

source

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.
source

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 that makes working with items easier.

source

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).
source

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.
source

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
source

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
source

pub async fn update<'a, T>( &self, conn: &mut RedisConn<'_>, uid: &str, item: &'a T, )
where T: 'a + Deserialize<'a>, &'a T: Serialize,

Update 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
  • Reset the item’s expiry time, given its been updated
source

pub async fn clear(&self, conn: &mut RedisConn<'_>)

Clear all the items in the list. (by just deleting the list itself, stored values will still live until their ttl but used a random uid so no conflicts)

Trait Implementations§

source§

impl Clone for RedisTempList

source§

fn clone(&self) -> RedisTempList

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for RedisTempList

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for RedisTempList

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for RedisTempList

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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

source§

fn from_event(ev: &Event) -> Result<T, FromFormDataError>

Tries to deserialize the data, given only the submit event.
source§

fn from_form_data(form_data: &FormData) -> Result<T, Error>

Tries to deserialize the data, given the actual form data.
source§

impl<T> FromRef<T> for T
where T: Clone,

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<T> FromRef<T> for T
where T: Clone,

source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
source§

impl<CustErr, T, Request> FromReq<Cbor, Request, CustErr> for T
where Request: Req<CustErr> + Send + 'static, T: DeserializeOwned,

source§

async fn from_req(req: Request) -> Result<T, ServerFnError<CustErr>>

Attempts to deserialize the arguments from a request.
source§

impl<CustErr, T, Request> FromReq<GetUrl, Request, CustErr> for T
where Request: Req<CustErr> + Send + 'static, T: DeserializeOwned,

source§

async fn from_req(req: Request) -> Result<T, ServerFnError<CustErr>>

Attempts to deserialize the arguments from a request.
source§

impl<CustErr, T, Request> FromReq<Json, Request, CustErr> for T
where Request: Req<CustErr> + Send + 'static, T: DeserializeOwned,

source§

async fn from_req(req: Request) -> Result<T, ServerFnError<CustErr>>

Attempts to deserialize the arguments from a request.
source§

impl<CustErr, T, Request> FromReq<PostUrl, Request, CustErr> for T
where Request: Req<CustErr> + Send + 'static, T: DeserializeOwned,

source§

async fn from_req(req: Request) -> Result<T, ServerFnError<CustErr>>

Attempts to deserialize the arguments from a request.
source§

impl<CustErr, T, Response> FromRes<Cbor, Response, CustErr> for T
where Response: ClientRes<CustErr> + Send, T: DeserializeOwned + Send,

source§

async fn from_res(res: Response) -> Result<T, ServerFnError<CustErr>>

Attempts to deserialize the outputs from a response.
source§

impl<CustErr, T, Response> FromRes<Json, Response, CustErr> for T
where Response: ClientRes<CustErr> + Send, T: DeserializeOwned + Send,

source§

async fn from_res(res: Response) -> Result<T, ServerFnError<CustErr>>

Attempts to deserialize the outputs from a response.
source§

impl<T> FutureExt for T

source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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<CustErr, T, Request> IntoReq<Cbor, Request, CustErr> for T
where Request: ClientReq<CustErr>, T: Serialize + Send,

source§

fn into_req( self, path: &str, accepts: &str, ) -> Result<Request, ServerFnError<CustErr>>

Attempts to serialize the arguments into an HTTP request.
source§

impl<CustErr, T, Request> IntoReq<GetUrl, Request, CustErr> for T
where Request: ClientReq<CustErr>, T: Serialize + Send,

source§

fn into_req( self, path: &str, accepts: &str, ) -> Result<Request, ServerFnError<CustErr>>

Attempts to serialize the arguments into an HTTP request.
source§

impl<CustErr, T, Request> IntoReq<Json, Request, CustErr> for T
where Request: ClientReq<CustErr>, T: Serialize + Send,

source§

fn into_req( self, path: &str, accepts: &str, ) -> Result<Request, ServerFnError<CustErr>>

Attempts to serialize the arguments into an HTTP request.
source§

impl<CustErr, T, Request> IntoReq<PostUrl, Request, CustErr> for T
where Request: ClientReq<CustErr>, T: Serialize + Send,

source§

fn into_req( self, path: &str, accepts: &str, ) -> Result<Request, ServerFnError<CustErr>>

Attempts to serialize the arguments into an HTTP request.
source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<CustErr, T, Response> IntoRes<Cbor, Response, CustErr> for T
where Response: Res<CustErr>, T: Serialize + Send,

source§

async fn into_res(self) -> Result<Response, ServerFnError<CustErr>>

Attempts to serialize the output into an HTTP response.
source§

impl<CustErr, T, Response> IntoRes<Json, Response, CustErr> for T
where Response: Res<CustErr>, T: Serialize + Send,

source§

async fn into_res(self) -> Result<Response, ServerFnError<CustErr>>

Attempts to serialize the output into an HTTP response.
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

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

§

type Output = T

Should always be Self
source§

impl<T> Serializable for T

source§

fn ser(&self) -> Result<String, SerializationError>

Serializes the object to a string.
source§

fn de(json: &str) -> Result<T, SerializationError>

Deserializes the object from some bytes.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<El> ElementDescriptorBounds for El
where El: Debug,