Skip to content

Commit e488930

Browse files
committed
Fix incorrect routing for XREAD/XREADGROUP command
The XREAD/XREADGROUP commands can have a variable number of args, and proper routing of the command relies on finding the key after the "STREAMS" keyword. This was failing to properly route the if the keyword was not uppercase. Fixes the matching logic make each arg uppercase before comparing to the "STREAMS" keyword.
1 parent 3da7c60 commit e488930

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/cluster.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ fn get_hashtag(key: &[u8]) -> Option<&[u8]> {
565565
}
566566
}
567567

568-
#[derive(Debug, Clone, Copy)]
568+
#[derive(Debug, Clone, Copy, PartialEq)]
569569
enum RoutingInfo {
570570
AllNodes,
571571
AllMasters,
@@ -619,7 +619,7 @@ impl RoutingInfo {
619619
b"XGROUP" | b"XINFO" => get_arg(&args, 2).and_then(RoutingInfo::for_key),
620620
b"XREAD" | b"XREADGROUP" => {
621621
let streams_position = args.iter().position(|a| match a {
622-
Value::Data(a) => a == b"STREAMS",
622+
Value::Data(a) => a.eq_ignore_ascii_case(b"STREAMS"),
623623
_ => false,
624624
})?;
625625
get_arg(&args, streams_position + 1).and_then(RoutingInfo::for_key)
@@ -744,12 +744,34 @@ fn get_slots(connection: &mut Connection) -> RedisResult<Vec<Slot>> {
744744

745745
#[cfg(test)]
746746
mod tests {
747-
use super::get_hashtag;
747+
use super::{cmd, get_hashtag, RoutingInfo};
748748

749749
#[test]
750750
fn test_get_hashtag() {
751751
assert_eq!(get_hashtag(&b"foo{bar}baz"[..]), Some(&b"bar"[..]));
752752
assert_eq!(get_hashtag(&b"foo{}{baz}"[..]), None);
753753
assert_eq!(get_hashtag(&b"foo{{bar}}zap"[..]), Some(&b"{bar"[..]));
754754
}
755+
756+
#[test]
757+
fn test_routing_info_mixed_capatalization() {
758+
let mut upper = cmd("XREAD");
759+
upper.arg("STREAMS").arg("foo").arg(0);
760+
761+
let mut lower = cmd("xread");
762+
lower.arg("streams").arg("foo").arg(0);
763+
764+
assert_eq!(
765+
RoutingInfo::for_packed_command(&upper.get_packed_command()).unwrap(),
766+
RoutingInfo::for_packed_command(&lower.get_packed_command()).unwrap()
767+
);
768+
769+
let mut mixed = cmd("xReAd");
770+
mixed.arg("StReAmS").arg("foo").arg(0);
771+
772+
assert_eq!(
773+
RoutingInfo::for_packed_command(&lower.get_packed_command()).unwrap(),
774+
RoutingInfo::for_packed_command(&mixed.get_packed_command()).unwrap()
775+
);
776+
}
755777
}

0 commit comments

Comments
 (0)