[−][src]Struct red::State
An opaque type that stores data.
This is used by both red and red-server independently, kind of like a singleton instance; however, you can make as many instances as you need.
Methods
impl State
[src]
Implements functionality for Store
. At time of writing this documentation,
it supports a few "commands" in a similar way to Redis: I've only
implemented the ones I actually need.
Full 1:1 mapping of Redis commands is not a goal, but it would be nice to keep following their spec closely.
pub fn new() -> Self
[src]
pub fn get(&mut self, key: &str) -> Option<&String>
[src]
Get the value of key.
Example
// The return value of the function is an option let value = state.get("someKey"); // Pattern match to retrieve the value match value { // The key was present Some(v) => println!("Value: {}", v), // The key was not present None => println!("Nope"), }
pub fn sadd(&mut self, member: String) -> bool
[src]
Add a new member to the set. If the member is already in the set, it will be ignored.
Example
state.sadd("BOOMBAYAH".to_string()); assert_eq!("BOOMBAYAH", state.smembers().next().unwrap());
pub fn smembers(&mut self) -> impl Iterator<Item = &String>
[src]
Returns an iterator to retrieve some or all the members of the set. The retrieval order is completely arbitrary.
Example
state.sadd("foo".to_string()); state.sadd("bar".to_string()); // Will print in an arbitrary order. for member in state.smembers() { println!("{}", member); }
For more detail about iterators, see the official docs.
pub fn srem(&mut self, member: &str) -> bool
[src]
Remove the specified member from the set.
Returns true if the member was in the set; false otherwise.
Example
state.sadd("mittsies".to_string()); assert_eq!(state.srem("mittsies"), true); assert_eq!(state.srem("mittsies"), false);
pub fn set(&mut self, key: String, value: String)
[src]
Set key to hold the specified value. If the key already holds a value, it is overwritten.
Example
state.set("someKey".to_string(), "Blade".to_string()); assert_eq!(state.get("someKey").unwrap(), "Blade");
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnwindSafe for State
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,