pub struct SimpleMap { /* private fields */ }Available on crate feature
mocks only.Expand description
A struct that implements some of the basic mapping functions. If callers require a mocking layer that stores and operates on real values then this struct is a good place to start.
Note: This does not support expirations or NX|XX qualifiers.
#[tokio::test]
async fn should_use_echo_mock() {
let config = RedisConfig {
mocks: Some(Arc::new(SimpleMap::new())),
..Default::default()
};
let client = Builder::from_config(config).build().unwrap();
client.init().await.expect("Failed to connect");
let actual: String = client
.set("foo", "bar", None, None, false)
.await
.expect("Failed to call SET");
assert_eq!(actual, "OK");
let actual: String = client.get("foo").await.expect("Failed to call GET");
assert_eq!(actual, "bar");
}Implementations§
source§impl SimpleMap
impl SimpleMap
sourcepub fn take(&self) -> HashMap<RedisKey, RedisValue>
pub fn take(&self) -> HashMap<RedisKey, RedisValue>
Take the inner map.
sourcepub fn inner(&self) -> HashMap<RedisKey, RedisValue>
pub fn inner(&self) -> HashMap<RedisKey, RedisValue>
Read a copy of the inner map.
sourcepub fn get(&self, args: Vec<RedisValue>) -> Result<RedisValue, RedisError>
pub fn get(&self, args: Vec<RedisValue>) -> Result<RedisValue, RedisError>
Perform a GET operation.
sourcepub fn set(&self, args: Vec<RedisValue>) -> Result<RedisValue, RedisError>
pub fn set(&self, args: Vec<RedisValue>) -> Result<RedisValue, RedisError>
Perform a SET operation.
sourcepub fn del(&self, args: Vec<RedisValue>) -> Result<RedisValue, RedisError>
pub fn del(&self, args: Vec<RedisValue>) -> Result<RedisValue, RedisError>
Perform a DEL operation.
Trait Implementations§
source§impl Mocks for SimpleMap
impl Mocks for SimpleMap
source§fn process_command(
&self,
command: MockCommand,
) -> Result<RedisValue, RedisError>
fn process_command( &self, command: MockCommand, ) -> Result<RedisValue, RedisError>
Intercept and process a Redis command, returning any
RedisValue. Read moresource§fn process_transaction(
&self,
commands: Vec<MockCommand>,
) -> Result<RedisValue, RedisError>
fn process_transaction( &self, commands: Vec<MockCommand>, ) -> Result<RedisValue, RedisError>
Intercept and process an entire transaction. The provided commands will not include
MULTI or EXEC. Read moreAuto Trait Implementations§
impl !Freeze for SimpleMap
impl !RefUnwindSafe for SimpleMap
impl Send for SimpleMap
impl !Sync for SimpleMap
impl Unpin for SimpleMap
impl UnwindSafe for SimpleMap
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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