Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for BZPOPMIN and BZPOPMAX #237

Merged
merged 2 commits into from Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/command_table.json
Expand Up @@ -49,11 +49,11 @@
},
"bzpopmax": {
"desc": "",
"supported": false
"supported": true
},
"bzpopmin": {
"desc": "",
"supported": false
"supported": true
},
"client": {
"desc": "",
Expand Down
4 changes: 2 additions & 2 deletions docs/command_table.md
Expand Up @@ -12,8 +12,8 @@
| blpop | True | User MUST specify timeout. |
| brpop | True | User MUST specify timeout. |
| brpoplpush | True | User MUST specify timeout. |
| bzpopmax | False | |
| bzpopmin | False | |
| bzpopmax | True | User MUST specify timeout. |
| bzpopmin | True | User MUST specify timeout. |
| client | False | |
| cluster | True | Only support the following sub commands: NODES, SLOTS, KEYSLOT. |
| command | False | |
Expand Down
19 changes: 14 additions & 5 deletions src/proxy/command.rs
Expand Up @@ -129,6 +129,8 @@ pub enum DataCmdType {
ZREMRANGEBYLEX,
ZREMRANGEBYRANK,
ZREMRANGEBYSCORE,
BZPOPMIN,
BZPOPMAX,
// Key commands
EXPIRE,
EXPIREAT,
Expand All @@ -142,6 +144,12 @@ pub enum DataCmdType {
}

impl DataCmdType {
fn is_blocking_cmd(self) -> bool {
match self {
Self::BZPOPMIN | Self::BZPOPMAX | Self::BLPOP | Self::BRPOP | Self::BRPOPLPUSH => true,
_ => false,
}
}
fn from_cmd_name(cmd_name: &[u8]) -> Self {
let mut stack_cmd_name = ArrayVec::<[u8; MAX_COMMAND_NAME_LENGTH]>::new();
for b in cmd_name {
Expand Down Expand Up @@ -207,6 +215,8 @@ impl DataCmdType {
b"UNLINK" => DataCmdType::UNLINK,
b"ZPOPMAX" => DataCmdType::ZPOPMAX,
b"ZPOPMIN" => DataCmdType::ZPOPMIN,
b"BZPOPMAX" => DataCmdType::BZPOPMAX,
b"BZPOPMIN" => DataCmdType::BZPOPMIN,
b"ZREM" => DataCmdType::ZREM,
cfeitong marked this conversation as resolved.
Show resolved Hide resolved
b"ZREMRANGEBYLEX" => DataCmdType::ZREMRANGEBYLEX,
b"ZREMRANGEBYRANK" => DataCmdType::ZREMRANGEBYRANK,
Expand Down Expand Up @@ -433,11 +443,10 @@ impl CmdReplySender {
match self.reply_sender.take() {
Some(reply_sender) => {
if let Err(CommandError::Dropped) = &res {
match self.data_cmd_type {
DataCmdType::BLPOP | DataCmdType::BRPOP | DataCmdType::BRPOPLPUSH => {
error!("blocking command is dropped")
}
_ => error!("command is dropped {:?}", Backtrace::new()),
if self.data_cmd_type.is_blocking_cmd() {
error!("blocking command is dropped");
} else {
error!("command is dropped {:?}", Backtrace::new());
}
}
Some(reply_sender.send(res).map_err(|_| CommandError::Canceled))
Expand Down