-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c213ad4
commit ac648fe
Showing
3 changed files
with
123 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use bytes::Bytes; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
use crate::commands::executable::Executable; | ||
use crate::commands::{CommandParser, CommandParserError}; | ||
use crate::frame::Frame; | ||
use crate::store::Store; | ||
use crate::Error; | ||
|
||
/// Returns PONG if no argument is provided, otherwise return a copy of the argument as a bulk. | ||
/// | ||
/// Ref: <https://redis.io/docs/latest/commands/ping> | ||
#[derive(Debug, PartialEq)] | ||
pub struct Ping { | ||
pub payload: Option<Bytes>, | ||
} | ||
|
||
impl Executable for Ping { | ||
fn exec(self, _store: Arc<Mutex<Store>>) -> Result<Frame, Error> { | ||
let res = self | ||
.payload | ||
.map_or(Frame::Bulk(Bytes::from("PONG")), Frame::Bulk); | ||
|
||
Ok(res) | ||
} | ||
} | ||
|
||
impl TryFrom<&mut CommandParser> for Ping { | ||
type Error = Error; | ||
|
||
fn try_from(parser: &mut CommandParser) -> Result<Self, Self::Error> { | ||
let payload = match parser.next_bytes() { | ||
Ok(payload) => Some(payload), | ||
Err(CommandParserError::EndOfStream) => None, | ||
Err(e) => return Err(e.into()), | ||
}; | ||
|
||
Ok(Self { payload }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use bytes::Bytes; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
use crate::commands::executable::Executable; | ||
use crate::commands::CommandParser; | ||
use crate::frame::Frame; | ||
use crate::store::Store; | ||
use crate::Error; | ||
|
||
/// Select the Redis logical database having the specified zero-based numeric index. New | ||
/// connections always use the database 0. | ||
/// | ||
/// Ref: <https://redis.io/docs/latest/commands/select> | ||
#[derive(Debug, PartialEq)] | ||
pub struct Select { | ||
/// The GUI clients we tested send this index value as bytes. Since we are not processing this | ||
/// value, there is no need to convert it to a number for now. | ||
pub index: Bytes, | ||
} | ||
|
||
impl Executable for Select { | ||
fn exec(self, _store: Arc<Mutex<Store>>) -> Result<Frame, Error> { | ||
Ok(Frame::Simple("OK".to_string())) | ||
} | ||
} | ||
|
||
impl TryFrom<&mut CommandParser> for Select { | ||
type Error = Error; | ||
|
||
fn try_from(parser: &mut CommandParser) -> Result<Self, Self::Error> { | ||
let index = parser.next_bytes()?; | ||
Ok(Self { index }) | ||
} | ||
} |