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,
impl<T> ListCache<T>where T: Serialize + DeserializeOwned,
sourcepub fn new(key: &str, client: Client) -> Self
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
sourcepub fn without_load(key: &str, client: Client) -> Self
pub fn without_load(key: &str, client: Client) -> Self
Creates a new ListCache without loading the list from the redis server.
pub fn pull(&mut self)
pub fn push_back(&mut self, val: T)
pub fn push_front(&mut self, val: T)
pub fn pop_back(&mut self) -> Option<T>
pub fn pop_front(&mut self) -> Option<T>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn insert(&mut self, index: usize, val: T)
pub fn front(&self) -> Option<&T>
pub fn back(&self) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Methods from Deref<Target = List<T>>§
sourcepub fn push_front(&mut self, val: &T)
pub fn push_front(&mut self, val: &T)
Add a value to the front of the list
Trait Implementations§
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> 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
Mutably borrows from an owned value. Read more