Struct dtypes::redis::List

source ·
pub struct List<T> { /* private fields */ }
Expand description

A list that is stored in Redis.

Example

use dtypes::redis::List;

let client = redis::Client::open("redis://localhost:6379").unwrap();
let mut list = List::new("test_list", client);
list.push_back(&1);
list.push_back(&2);
assert_eq!(list.len(), 2);
assert_eq!(list.pop_front(), Some(1));
list.clear();

Implementations§

source§

impl<T> List<T>where T: Serialize + DeserializeOwned,

source

pub fn new(key: &str, client: Client) -> Self

Creates a new List

There is no with_value method like (Generic::with_value)crate::redis::Generic::with_value because it is not possible to provide a good default behaviour in redis. So you have to think about, how you want to handle already stored values in redis. If you want a small performance boost, look at ListCache.

source

pub fn iter(&self) -> ListIter<'_, T>

Returns an iterator over the list.

source

pub fn push_front(&mut self, val: &T)

Add a value to the front of the list

source

pub fn push_back(&mut self, val: &T)

Add a value to the back of the list

source

pub fn pop_front(&mut self) -> Option<T>

Removes and returns the first value of the list

source

pub fn pop_back(&mut self) -> Option<T>

Removes and returns the last value of the list

source

pub fn len(&self) -> usize

Returns the length of the list

source

pub fn clear(&self)

Removes all values from the list

source

pub fn contains(&self, val: &T) -> boolwhere T: PartialEq,

Returns true if the list contains the value

source

pub fn is_empty(&self) -> bool

Returns true if the list is empty

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for List<T>

§

impl<T> Send for List<T>where T: Send,

§

impl<T> Sync for List<T>where T: Sync,

§

impl<T> Unpin for List<T>where T: Unpin,

§

impl<T> !UnwindSafe for List<T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.