Struct dtypes::redis::ListCache

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

A list that caches the values in memory It improves the performance, if you perform a lot of read only operations on the list.

All manipulations are done on the cache and synced with the redis server.

Example

use dtypes::redis::{ListCache, Mutex};

let client = redis::Client::open("redis://localhost:6379").unwrap();
let mut list = ListCache::new("test_list2", 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> ListCache<T>where T: Serialize + DeserializeOwned,

source

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

Creates a new ListCache The list is loaded from the redis server. If you want to create an empty list, use ListCache::without_load

source

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

Creates a new ListCache without loading the list from the redis server.

source

pub fn pull(&mut self)

source

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

source

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

source

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

source

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

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

pub fn insert(&mut self, index: usize, val: T)

source

pub fn front(&self) -> Option<&T>

source

pub fn back(&self) -> Option<&T>

source

pub fn get(&self, index: usize) -> Option<&T>

Methods from Deref<Target = List<T>>§

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

Trait Implementations§

source§

impl<T> Deref for ListCache<T>

§

type Target = List<T>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T> DerefMut for ListCache<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for ListCache<T>

§

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

§

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

§

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

§

impl<T> !UnwindSafe for ListCache<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.